Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
bc9fe742
Unverified
Commit
bc9fe742
authored
Feb 19, 2020
by
Marc Cornellà
Committed by
GitHub
Feb 19, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8651 from mcornella/random-theme-refactor
Add random theme and consolidate logic from init and themes plugin
parents
d76258ff
3d4890dc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
40 deletions
+63
-40
oh-my-zsh.sh
oh-my-zsh.sh
+6
-19
_theme
plugins/themes/_theme
+0
-3
themes.plugin.zsh
plugins/themes/themes.plugin.zsh
+19
-18
random.zsh-theme
themes/random.zsh-theme
+38
-0
No files found.
oh-my-zsh.sh
View file @
bc9fe742
...
@@ -97,25 +97,12 @@ done
...
@@ -97,25 +97,12 @@ done
unset
config_file
unset
config_file
# Load the theme
# Load the theme
if
[[
"
$ZSH_THEME
"
==
"random"
]]
;
then
if
[
!
"
$ZSH_THEME
"
=
""
]
;
then
if
[[
"
${
(t)ZSH_THEME_RANDOM_CANDIDATES
}
"
=
"array"
]]
&&
[[
"
${#
ZSH_THEME_RANDOM_CANDIDATES
[@]
}
"
-gt
0
]]
;
then
if
[
-f
"
$ZSH_CUSTOM
/
$ZSH_THEME
.zsh-theme"
]
;
then
themes
=(
$ZSH
/themes/
${
^ZSH_THEME_RANDOM_CANDIDATES
}
.zsh-theme
)
source
"
$ZSH_CUSTOM
/
$ZSH_THEME
.zsh-theme"
elif
[
-f
"
$ZSH_CUSTOM
/themes/
$ZSH_THEME
.zsh-theme"
]
;
then
source
"
$ZSH_CUSTOM
/themes/
$ZSH_THEME
.zsh-theme"
else
else
themes
=(
$ZSH
/themes/
*
zsh-theme
)
source
"
$ZSH
/themes/
$ZSH_THEME
.zsh-theme"
fi
N
=
${#
themes
[@]
}
((
N
=(
RANDOM%N
)
+1
))
RANDOM_THEME
=
${
themes
[
$N
]
}
source
"
$RANDOM_THEME
"
echo
"[oh-my-zsh] Random theme '
$RANDOM_THEME
' loaded..."
else
if
[
!
"
$ZSH_THEME
"
=
""
]
;
then
if
[
-f
"
$ZSH_CUSTOM
/
$ZSH_THEME
.zsh-theme"
]
;
then
source
"
$ZSH_CUSTOM
/
$ZSH_THEME
.zsh-theme"
elif
[
-f
"
$ZSH_CUSTOM
/themes/
$ZSH_THEME
.zsh-theme"
]
;
then
source
"
$ZSH_CUSTOM
/themes/
$ZSH_THEME
.zsh-theme"
else
source
"
$ZSH
/themes/
$ZSH_THEME
.zsh-theme"
fi
fi
fi
fi
fi
plugins/themes/_theme
deleted
100644 → 0
View file @
d76258ff
#compdef theme
_arguments "1: :($(lstheme | tr "\n" " "))"
plugins/themes/themes.plugin.zsh
View file @
bc9fe742
function
theme
function
theme
{
{
:
${
1
:
=random
}
# Use random theme if none provided
if
[
-z
"
$1
"
]
||
[
"
$1
"
=
"random"
]
;
then
themes
=(
$ZSH
/themes/
*
zsh-theme
)
if
[[
-f
"
$ZSH_CUSTOM
/
$1
.zsh-theme"
]]
;
then
N
=
${#
themes
[@]
}
source
"
$ZSH_CUSTOM
/
$1
.zsh-theme"
((
N
=(
RANDOM%N
)
+1
))
elif
[[
-f
"
$ZSH_CUSTOM
/themes/
$1
.zsh-theme"
]]
;
then
RANDOM_THEME
=
${
themes
[
$N
]
}
source
"
$ZSH_CUSTOM
/themes/
$1
.zsh-theme"
source
"
$RANDOM_THEME
"
elif
[[
-f
"
$ZSH
/themes/
$1
.zsh-theme"
]]
;
then
echo
"[oh-my-zsh] Random theme '
$RANDOM_THEME
' loaded...
"
source
"
$ZSH
/themes/
$1
.zsh-theme
"
else
else
if
[
-f
"
$ZSH_CUSTOM
/themes/
$1
.zsh-theme"
]
echo
"
$0
: Theme '
$1
' not found"
then
return
1
source
"
$ZSH_CUSTOM
/themes/
$1
.zsh-theme"
else
source
"
$ZSH
/themes/
$1
.zsh-theme"
fi
fi
fi
}
}
function
lstheme
function
_theme
{
{
_arguments
"1: :(
$(
lstheme
)
)"
}
compdef _theme theme
function
lstheme
{
# Resources:
# Resources:
# http://zsh.sourceforge.net/Doc/Release/Expansion.html#Modifiers
# http://zsh.sourceforge.net/Doc/Release/Expansion.html#Modifiers
# http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Qualifiers
# http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Qualifiers
print
-l
{
$ZSH
,
$ZSH_CUSTOM
}
/themes/
*
.zsh-theme
(
N:t:r
)
print
"
$ZSH_CUSTOM
"
/
*
.zsh-theme
(
N:t:r
)
{
"
$ZSH_CUSTOM
"
,
"
$ZSH
"
}
/themes/
*
.zsh-theme
(
N:t:r
)
}
}
themes/random.zsh-theme
0 → 100644
View file @
bc9fe742
# Make themes a unique array
typeset -Ua themes
if [[ "${(t)ZSH_THEME_RANDOM_CANDIDATES}" = array && ${#ZSH_THEME_RANDOM_CANDIDATES[@]} -gt 0 ]]; then
# Use ZSH_THEME_RANDOM_CANDIDATES if properly defined
themes=($ZSH_THEME_RANDOM_CANDIDATES)
else
# Look for themes in $ZSH_CUSTOM and $ZSH and add only the theme name
themes=(
"$ZSH_CUSTOM"/*.zsh-theme(N:t:r)
"$ZSH_CUSTOM"/themes/*.zsh-theme(N:t:r)
"$ZSH"/themes/*.zsh-theme(N:t:r)
)
# Remove blacklisted themes from the list
for theme in ${ZSH_THEME_RANDOM_BLACKLIST[@]}; do
themes=("${(@)themes:#$theme}")
done
fi
# Choose a theme out of the pool of candidates
N=${#themes[@]}
(( N = (RANDOM%N) + 1 ))
RANDOM_THEME="${themes[$N]}"
unset N themes theme
# Source theme
if [[ -f "$ZSH_CUSTOM/$RANDOM_THEME.zsh-theme" ]]; then
source "$ZSH_CUSTOM/$RANDOM_THEME.zsh-theme"
elif [[ -f "$ZSH_CUSTOM/themes/$RANDOM_THEME.zsh-theme" ]]; then
source "$ZSH_CUSTOM/themes/$RANDOM_THEME.zsh-theme"
elif [[ -f "$ZSH/themes/$RANDOM_THEME.zsh-theme" ]]; then
source "$ZSH/themes/$RANDOM_THEME.zsh-theme"
else
echo "[oh-my-zsh] Random theme '${RANDOM_THEME}' not found"
return 1
fi
echo "[oh-my-zsh] Random theme '${RANDOM_THEME}' loaded"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment