mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-12 21:39:48 +01:00
fixed theme chooser + options + list available themes + show all themes
This commit is contained in:
parent
d15d3a5b01
commit
cbf662744f
1 changed files with 69 additions and 21 deletions
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh
|
#!/bin/zsh
|
||||||
|
|
||||||
# Zsh Theme Chooser by fox (fox91 at anche dot no)
|
# Zsh Theme Chooser by fox (fox91 at anche dot no)
|
||||||
# This program is free software. It comes without any warranty, to
|
# This program is free software. It comes without any warranty, to
|
||||||
|
@ -9,9 +9,10 @@
|
||||||
|
|
||||||
THEMES_DIR="$ZSH/themes"
|
THEMES_DIR="$ZSH/themes"
|
||||||
FAVLIST="${HOME}/.zsh_favlist"
|
FAVLIST="${HOME}/.zsh_favlist"
|
||||||
|
source $ZSH/oh-my-zsh.sh
|
||||||
|
|
||||||
function noyes() {
|
function noyes() {
|
||||||
read -p "$1 [y/N] " a
|
read "a?$1 [y/N] "
|
||||||
if [[ $a == "N" || $a == "n" || $a = "" ]]; then
|
if [[ $a == "N" || $a == "n" || $a = "" ]]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
@ -20,29 +21,76 @@ function noyes() {
|
||||||
|
|
||||||
function theme_preview() {
|
function theme_preview() {
|
||||||
THEME=$1
|
THEME=$1
|
||||||
THEME_NAME=`echo $THEME | sed s/\.zsh-theme//`
|
THEME_NAME=`echo $THEME | sed s/\.zsh-theme$//`
|
||||||
export ZDOTDIR="$(mktemp -d tmp.zshXXXX)"
|
print "$fg[blue]${(l.((${COLUMNS}-${#THEME_NAME}-5))..─.)}$reset_color $THEME_NAME $fg[blue]───$reset_color"
|
||||||
|
source "$THEMES_DIR/$THEME"
|
||||||
cat <<-EOF >"$ZDOTDIR/.zshrc"
|
print -P $PROMPT
|
||||||
ZSH_THEME="$THEME_NAME"
|
|
||||||
source $ZSH/oh-my-zsh.sh
|
|
||||||
EOF
|
|
||||||
zsh
|
|
||||||
rm -rf "$ZDOTDIR"
|
|
||||||
|
|
||||||
echo
|
|
||||||
noyes "Do you want to add it to your favourite list ($FAVLIST)?" || \
|
|
||||||
echo $THEME_NAME >> $FAVLIST
|
|
||||||
echo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function banner() {
|
||||||
echo
|
echo
|
||||||
echo "[0;1;35;95m╺━[0;1;31;91m┓┏[0;1;33;93m━┓[0;1;32;92m╻[0m [0;1;36;96m╻[0m [0;1;35;95m╺┳[0;1;31;91m╸╻[0m [0;1;33;93m╻[0;1;32;92m┏━[0;1;36;96m╸┏[0;1;34;94m┳┓[0;1;35;95m┏━[0;1;31;91m╸[0m [0;1;32;92m┏━[0;1;36;96m╸╻[0m [0;1;34;94m╻[0;1;35;95m┏━[0;1;31;91m┓┏[0;1;33;93m━┓[0;1;32;92m┏━[0;1;36;96m┓┏[0;1;34;94m━╸[0;1;35;95m┏━[0;1;31;91m┓[0m"
|
echo "[0;1;35;95m╺━[0;1;31;91m┓┏[0;1;33;93m━┓[0;1;32;92m╻[0m [0;1;36;96m╻[0m [0;1;35;95m╺┳[0;1;31;91m╸╻[0m [0;1;33;93m╻[0;1;32;92m┏━[0;1;36;96m╸┏[0;1;34;94m┳┓[0;1;35;95m┏━[0;1;31;91m╸[0m [0;1;32;92m┏━[0;1;36;96m╸╻[0m [0;1;34;94m╻[0;1;35;95m┏━[0;1;31;91m┓┏[0;1;33;93m━┓[0;1;32;92m┏━[0;1;36;96m┓┏[0;1;34;94m━╸[0;1;35;95m┏━[0;1;31;91m┓[0m"
|
||||||
echo "[0;1;31;91m┏━[0;1;33;93m┛┗[0;1;32;92m━┓[0;1;36;96m┣━[0;1;34;94m┫[0m [0;1;31;91m┃[0m [0;1;33;93m┣[0;1;32;92m━┫[0;1;36;96m┣╸[0m [0;1;34;94m┃[0;1;35;95m┃┃[0;1;31;91m┣╸[0m [0;1;36;96m┃[0m [0;1;34;94m┣[0;1;35;95m━┫[0;1;31;91m┃[0m [0;1;33;93m┃┃[0m [0;1;32;92m┃[0;1;36;96m┗━[0;1;34;94m┓┣[0;1;35;95m╸[0m [0;1;31;91m┣┳[0;1;33;93m┛[0m"
|
echo "[0;1;31;91m┏━[0;1;33;93m┛┗[0;1;32;92m━┓[0;1;36;96m┣━[0;1;34;94m┫[0m [0;1;31;91m┃[0m [0;1;33;93m┣[0;1;32;92m━┫[0;1;36;96m┣╸[0m [0;1;34;94m┃[0;1;35;95m┃┃[0;1;31;91m┣╸[0m [0;1;36;96m┃[0m [0;1;34;94m┣[0;1;35;95m━┫[0;1;31;91m┃[0m [0;1;33;93m┃┃[0m [0;1;32;92m┃[0;1;36;96m┗━[0;1;34;94m┓┣[0;1;35;95m╸[0m [0;1;31;91m┣┳[0;1;33;93m┛[0m"
|
||||||
echo "[0;1;33;93m┗━[0;1;32;92m╸┗[0;1;36;96m━┛[0;1;34;94m╹[0m [0;1;35;95m╹[0m [0;1;33;93m╹[0m [0;1;32;92m╹[0m [0;1;36;96m╹[0;1;34;94m┗━[0;1;35;95m╸╹[0m [0;1;31;91m╹[0;1;33;93m┗━[0;1;32;92m╸[0m [0;1;34;94m┗━[0;1;35;95m╸╹[0m [0;1;31;91m╹[0;1;33;93m┗━[0;1;32;92m┛┗[0;1;36;96m━┛[0;1;34;94m┗━[0;1;35;95m┛┗[0;1;31;91m━╸[0;1;33;93m╹┗[0;1;32;92m╸[0m"
|
echo "[0;1;33;93m┗━[0;1;32;92m╸┗[0;1;36;96m━┛[0;1;34;94m╹[0m [0;1;35;95m╹[0m [0;1;33;93m╹[0m [0;1;32;92m╹[0m [0;1;36;96m╹[0;1;34;94m┗━[0;1;35;95m╸╹[0m [0;1;31;91m╹[0;1;33;93m┗━[0;1;32;92m╸[0m [0;1;34;94m┗━[0;1;35;95m╸╹[0m [0;1;31;91m╹[0;1;33;93m┗━[0;1;32;92m┛┗[0;1;36;96m━┛[0;1;34;94m┗━[0;1;35;95m┛┗[0;1;31;91m━╸[0;1;33;93m╹┗[0;1;32;92m╸[0m"
|
||||||
echo
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
for i in $(ls $THEMES_DIR); do
|
function usage() {
|
||||||
echo "Now showing theme $i"
|
echo "Usage: $0 [options] [theme]"
|
||||||
theme_preview $i
|
echo
|
||||||
|
echo "Options"
|
||||||
|
echo " -l List available themes"
|
||||||
|
echo " -s Show all themes"
|
||||||
|
echo " -h Get this help message"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function list_themes() {
|
||||||
|
for THEME in $(ls $THEMES_DIR); do
|
||||||
|
THEME_NAME=`echo $THEME | sed s/\.zsh-theme$//`
|
||||||
|
echo $THEME_NAME
|
||||||
done
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function insert_favlist() {
|
||||||
|
if grep -q "$THEME_NAME" $FAVLIST 2> /dev/null ; then
|
||||||
|
echo "Already in favlist"
|
||||||
|
else
|
||||||
|
echo $THEME_NAME >> $FAVLIST
|
||||||
|
echo "Saved to favlist"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function theme_chooser() {
|
||||||
|
for THEME in $(ls $THEMES_DIR); do
|
||||||
|
echo
|
||||||
|
theme_preview $THEME
|
||||||
|
echo
|
||||||
|
if [[ -z $1 ]]; then
|
||||||
|
noyes "Do you want to add it to your favourite list ($FAVLIST)?" || \
|
||||||
|
insert_favlist $THEME_NAME
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
while getopts ":lhs" Option
|
||||||
|
do
|
||||||
|
case $Option in
|
||||||
|
l ) list_themes ;;
|
||||||
|
s ) theme_chooser 0 ;;
|
||||||
|
h ) usage ;;
|
||||||
|
* ) usage ;; # Default.
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -z $Option ]]; then
|
||||||
|
if [[ -z $1 ]]; then
|
||||||
|
banner
|
||||||
|
echo
|
||||||
|
theme_chooser
|
||||||
|
else
|
||||||
|
theme_preview $1".zsh-theme"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in a new issue