From fea4e54b1053764df10f507c233286281133fe90 Mon Sep 17 00:00:00 2001 From: fox Date: Tue, 19 Jul 2011 21:47:26 +0200 Subject: [PATCH 1/5] added theme chooser --- tools/theme_chooser.sh | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 tools/theme_chooser.sh diff --git a/tools/theme_chooser.sh b/tools/theme_chooser.sh new file mode 100755 index 000000000..2413bfee8 --- /dev/null +++ b/tools/theme_chooser.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +# Zsh Theme Chooser by fox (fox91 at anche dot no) +# This program is free software. It comes without any warranty, to +# the extent permitted by applicable law. You can redistribute it +# and/or modify it under the terms of the Do What The Fuck You Want +# To Public License, Version 2, as published by Sam Hocevar. See +# http://sam.zoy.org/wtfpl/COPYING for more details. + +THEMES_DIR="$ZSH/themes" +FAVLIST="~/.zsh_favlist" + +function noyes() { + read -p "$1 [y/N]" a + if [[ $a == "N" || $a == "n" || $a = "" ]]; then + return 0 + fi + return 1 +} + +function theme_preview() { + THEME=$1 + export ZDOTDIR="$(mktemp -d)" + +cat <<-EOF >"$ZDOTDIR/.zshrc" + source ~/.zshrc + source "$THEMES_DIR/$THEME" +EOF + zsh + rm -rf "$ZDOTDIR" + + echo + noyes "Do you want to add it to your favourite list?" && \ + echo $THEME >> $FAVLIST + echo +} + +echo +echo "╺━┓┏━┓╻ ╻ ╺┳╸╻ ╻┏━╸┏┳┓┏━╸ ┏━╸╻ ╻┏━┓┏━┓┏━┓┏━╸┏━┓" +echo "┏━┛┗━┓┣━┫ ┃ ┣━┫┣╸ ┃┃┃┣╸ ┃ ┣━┫┃ ┃┃ ┃┗━┓┣╸ ┣┳┛" +echo "┗━╸┗━┛╹ ╹ ╹ ╹ ╹┗━╸╹ ╹┗━╸ ┗━╸╹ ╹┗━┛┗━┛┗━┛┗━╸╹┗╸" +echo + +for i in $(ls $THEMES_DIR); do + echo "Now showing theme $i" + theme_preview $i +done From 5d5d2f94be7a13c3a5069bed6bfc2070fa7f014c Mon Sep 17 00:00:00 2001 From: fox Date: Tue, 19 Jul 2011 22:02:34 +0200 Subject: [PATCH 2/5] fox's theme + theme chooser fixes --- themes/fox.zsh-theme | 8 ++++++++ tools/theme_chooser.sh | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 themes/fox.zsh-theme diff --git a/themes/fox.zsh-theme b/themes/fox.zsh-theme new file mode 100644 index 000000000..1959853cf --- /dev/null +++ b/themes/fox.zsh-theme @@ -0,0 +1,8 @@ +#fox theme +PROMPT='%{$fg[cyan]%}┌[%{$fg_bold[white]%}%n%{$reset_color%}%{$fg[cyan]%}☮%{$fg_bold[white]%}%M%{$reset_color%}%{$fg[cyan]%}]%{$fg[white]%}-%{$fg[cyan]%}(%{$fg_bold[white]%}%~%{$reset_color%}%{$fg[cyan]%})$(git_prompt_info) +└> % %{$reset_color%}' + +ZSH_THEME_GIT_PROMPT_PREFIX="-[%{$reset_color%}%{$fg[white]%}git://%{$fg_bold[white]%}" +ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}%{$fg[cyan]%}]-" +ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[red]%}✗%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_CLEAN=" %{$fg[green]%}✔%{$reset_color%}" diff --git a/tools/theme_chooser.sh b/tools/theme_chooser.sh index 2413bfee8..50f80f092 100755 --- a/tools/theme_chooser.sh +++ b/tools/theme_chooser.sh @@ -8,10 +8,10 @@ # http://sam.zoy.org/wtfpl/COPYING for more details. THEMES_DIR="$ZSH/themes" -FAVLIST="~/.zsh_favlist" +FAVLIST="${HOME}/.zsh_favlist" function noyes() { - read -p "$1 [y/N]" a + read -p "$1 [y/N] " a if [[ $a == "N" || $a == "n" || $a = "" ]]; then return 0 fi @@ -30,7 +30,7 @@ EOF rm -rf "$ZDOTDIR" echo - noyes "Do you want to add it to your favourite list?" && \ + noyes "Do you want to add it to your favourite list ($FAVLIST)?" || \ echo $THEME >> $FAVLIST echo } From 76dd2d8b05cb1b8d34653732e8b3939f68e8a67a Mon Sep 17 00:00:00 2001 From: fox Date: Sun, 24 Jul 2011 11:58:41 +0200 Subject: [PATCH 3/5] mac os fix --- tools/theme_chooser.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/theme_chooser.sh b/tools/theme_chooser.sh index 50f80f092..af861a15b 100755 --- a/tools/theme_chooser.sh +++ b/tools/theme_chooser.sh @@ -20,7 +20,7 @@ function noyes() { function theme_preview() { THEME=$1 - export ZDOTDIR="$(mktemp -d)" + export ZDOTDIR="$(mktemp -d tmp.zshXXXX)" cat <<-EOF >"$ZDOTDIR/.zshrc" source ~/.zshrc From d15d3a5b01a527d8642cc0b173a2f8d1b92332c0 Mon Sep 17 00:00:00 2001 From: fox Date: Sun, 24 Jul 2011 20:51:27 +0200 Subject: [PATCH 4/5] global zsh config --- tools/theme_chooser.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/theme_chooser.sh b/tools/theme_chooser.sh index af861a15b..ea5191afe 100755 --- a/tools/theme_chooser.sh +++ b/tools/theme_chooser.sh @@ -20,18 +20,19 @@ function noyes() { function theme_preview() { THEME=$1 + THEME_NAME=`echo $THEME | sed s/\.zsh-theme//` export ZDOTDIR="$(mktemp -d tmp.zshXXXX)" cat <<-EOF >"$ZDOTDIR/.zshrc" - source ~/.zshrc - source "$THEMES_DIR/$THEME" + 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 >> $FAVLIST + echo $THEME_NAME >> $FAVLIST echo } From cbf662744ffcf998829cabbd7b2550861c13d1d8 Mon Sep 17 00:00:00 2001 From: fox Date: Wed, 3 Aug 2011 09:42:16 +0200 Subject: [PATCH 5/5] fixed theme chooser + options + list available themes + show all themes --- tools/theme_chooser.sh | 90 ++++++++++++++++++++++++++++++++---------- 1 file changed, 69 insertions(+), 21 deletions(-) diff --git a/tools/theme_chooser.sh b/tools/theme_chooser.sh index ea5191afe..4d7047444 100755 --- a/tools/theme_chooser.sh +++ b/tools/theme_chooser.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/zsh # Zsh Theme Chooser by fox (fox91 at anche dot no) # This program is free software. It comes without any warranty, to @@ -9,9 +9,10 @@ THEMES_DIR="$ZSH/themes" FAVLIST="${HOME}/.zsh_favlist" +source $ZSH/oh-my-zsh.sh function noyes() { - read -p "$1 [y/N] " a + read "a?$1 [y/N] " if [[ $a == "N" || $a == "n" || $a = "" ]]; then return 0 fi @@ -20,29 +21,76 @@ function noyes() { function theme_preview() { THEME=$1 - THEME_NAME=`echo $THEME | sed s/\.zsh-theme//` - export ZDOTDIR="$(mktemp -d tmp.zshXXXX)" - -cat <<-EOF >"$ZDOTDIR/.zshrc" - ZSH_THEME="$THEME_NAME" - source $ZSH/oh-my-zsh.sh -EOF - zsh - rm -rf "$ZDOTDIR" + THEME_NAME=`echo $THEME | sed s/\.zsh-theme$//` + print "$fg[blue]${(l.((${COLUMNS}-${#THEME_NAME}-5))..─.)}$reset_color $THEME_NAME $fg[blue]───$reset_color" + source "$THEMES_DIR/$THEME" + print -P $PROMPT +} +function banner() { echo - noyes "Do you want to add it to your favourite list ($FAVLIST)?" || \ - echo $THEME_NAME >> $FAVLIST + echo "╺━┓┏━┓╻ ╻ ╺┳╸╻ ╻┏━╸┏┳┓┏━╸ ┏━╸╻ ╻┏━┓┏━┓┏━┓┏━╸┏━┓" + echo "┏━┛┗━┓┣━┫ ┃ ┣━┫┣╸ ┃┃┃┣╸ ┃ ┣━┫┃ ┃┃ ┃┗━┓┣╸ ┣┳┛" + echo "┗━╸┗━┛╹ ╹ ╹ ╹ ╹┗━╸╹ ╹┗━╸ ┗━╸╹ ╹┗━┛┗━┛┗━┛┗━╸╹┗╸" echo } -echo -echo "╺━┓┏━┓╻ ╻ ╺┳╸╻ ╻┏━╸┏┳┓┏━╸ ┏━╸╻ ╻┏━┓┏━┓┏━┓┏━╸┏━┓" -echo "┏━┛┗━┓┣━┫ ┃ ┣━┫┣╸ ┃┃┃┣╸ ┃ ┣━┫┃ ┃┃ ┃┗━┓┣╸ ┣┳┛" -echo "┗━╸┗━┛╹ ╹ ╹ ╹ ╹┗━╸╹ ╹┗━╸ ┗━╸╹ ╹┗━┛┗━┛┗━┛┗━╸╹┗╸" -echo +function usage() { + echo "Usage: $0 [options] [theme]" + echo + echo "Options" + echo " -l List available themes" + echo " -s Show all themes" + echo " -h Get this help message" + exit 1 +} -for i in $(ls $THEMES_DIR); do - echo "Now showing theme $i" - theme_preview $i +function list_themes() { + for THEME in $(ls $THEMES_DIR); do + THEME_NAME=`echo $THEME | sed s/\.zsh-theme$//` + echo $THEME_NAME + 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