diff --git a/README.markdown b/README.markdown index c411ec9..af9434f 100644 --- a/README.markdown +++ b/README.markdown @@ -44,11 +44,6 @@ just add a new file (ending in .load) into the `custom/` directory. I'm hoping to collect a bunch of themes for our command prompts. You can see existing ones in the [themes](themes/) directory. -## Integrating oh-my-fish themes with fish_config - -Fish provides fish_config, a web portal where you can modify some configurations, including changing your fish_prompt. By default, fish_config comes with a series of prepackaged themes. Running copy_prompts.fish installed with oh-my-fish will integrate oh-my-fish's provided themes with fish_config and allow you to choose a custom theme as your prompt. - - ## Switching to fish If you wish to use fish as your default shell, use the following command: diff --git a/copy_prompts.fish b/copy_prompts.fish deleted file mode 100755 index ee1e442..0000000 --- a/copy_prompts.fish +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/local/bin/fish -# This script will create a symbolic link between all themes included in oh-my-fish to the sample prompts -# This will allow the user to choose an oh-my-fish theme while using the stock fish_config web application -for themePath in (ls $fish_path/themes/*/fish_prompt.fish) - set themeName (echo $themePath | sed "s/.*themes\///;s/\/fish_prompt.fish//") - echo "Adding $themeName to the sample prompts" - ln -sf $themePath $__fish_datadir/tools/web_config/sample_prompts/$themeName.fish -end diff --git a/functions/_append_path.fish b/functions/_append_path.fish new file mode 100644 index 0000000..1516adb --- /dev/null +++ b/functions/_append_path.fish @@ -0,0 +1,13 @@ +# Appends the path to the specified path list. If no list specified, +# defaults to $PATH +function _append_path + set -l path PATH + + if test (echo $argv | wc -w) -eq 2 + set path $argv[2] + end + + if test -d $argv[1]; and not contains $argv[1] $$path + set $path $argv[1] $$path + end +end diff --git a/functions/source_script.fish b/functions/source_script.fish new file mode 100644 index 0000000..c9f7ebe --- /dev/null +++ b/functions/source_script.fish @@ -0,0 +1,97 @@ +# Cloned from https://github.com/fish-shell/fish-shell/issues/522 + +function source_script --description 'Source sh/csh file' + set -l ext + set -l type + + while true + switch $argv[1] + case '--sh' + set type sh + case '--csh' + set type csh + case '--bash' + set type bash + case '--ext' + set ext 1 + case '*' + break + end + set -e argv[1] + end + + if not test "$type" + for f in $argv + switch $f + case '*.sh' + set type bash + break + case '*.csh' '*.tcsh' + set type csh + break + end + end + end + + set -l exe + set -l source + + switch "$type" + case bash + set exe /bin/bash + set source . + case sh + set exe /bin/sh + set source . + case csh + set exe /bin/tcsh + set source source + case '*' + echo Unknown source type for "'$argv'" + end + + if test "$ext" + eval "exec $exe -c '$source $argv; exec fish'" + else + set -l f1 (mktemp -t tmp.XXXXXXXXXX) + set -l f2 (mktemp -t tmp.XXXXXXXXXX) + eval $exe -c "'env | sort > $f1; $source $argv; env | sort > $f2'" + + set -l filter "(^[^\+-]|^\+\+\+|^---|^[\+-]_|^[\+-]PIPESTATUS|^[\+-]COLUMNS)" + set -l pattern 's/[:]\{0,1\}\([^:]\+\)/"\1" /g' + + set -l IFS '=' + set -l diffopts --old-line-format '-=%L' --new-line-format '+=%L' --unchanged-line-format '' + diff $diffopts $f1 $f2 | grep -vE $filter | while read -l state var value + switch $state$var + case -PATH + continue + + case +PATH + eval set value (echo $value | tr : ' ') + for pt in $value + contains $pt $PATH; and continue + if not test -d $pt + echo "Unable to add '$pt' to \$PATH. Check existance." + continue + end + #echo set -gx PATH $PATH $pt + set -gx PATH $PATH $pt > /dev/null + end + + case '-*' + #echo unset $var + set -e $var + + case '+*' + eval set -gx $var (echo $value | sed $pattern) + #echo Set $var to: (echo $value | sed $pattern) + + case '*' + echo Source error! Invalid case "'$state$var'" + end + end + + rm $f1 $f2 > /dev/null + end +end diff --git a/oh-my-fish.fish b/oh-my-fish.fish index 72f512e..71d1182 100644 --- a/oh-my-fish.fish +++ b/oh-my-fish.fish @@ -2,30 +2,27 @@ # Helper functions ### +function _test_dir + set -l path $argv[1] + set -l paths $argv[2] + + return (test -d $path; and not contains $path $paths) +end + function _fish_add_plugin set -l plugin $argv[1] set -l plugin_path "plugins/$plugin" - if test -d $fish_path/$plugin_path - set fish_function_path $fish_path/$plugin_path $fish_function_path - end - - if test -d $fish_custom/$plugin_path - set fish_function_path $fish_custom/$plugin_path $fish_function_path - end + _append_path $fish_path/$plugin_path fish_function_path + _append_path $fish_custom/$plugin_path fish_function_path end function _fish_add_completion set -l plugin $argv[1] set -l completion_path "plugins/$plugin/completions" - if test -d $fish_path/$completion_path - set fish_complete_path $fish_path/$completion_path $fish_complete_path - end - - if test -d $fish_custom/$completion_path - set fish_complete_path $fish_custom/$completion_path $fish_complete_path - end + _append_path $fish_path/$completion_path fish_complete_path + _append_path $fish_custom/$completion_path fish_complete_path end function _fish_source_plugin_load_file @@ -42,13 +39,8 @@ function _fish_source_plugin_load_file end function _fish_load_theme - if test -d $fish_path/themes/$fish_theme - set fish_function_path $fish_path/themes/$fish_theme $fish_function_path - end - - if test -d $fish_custom/themes/$fish_theme - set fish_function_path $fish_custom/themes/$fish_theme $fish_function_path - end + _append_path $fish_path/themes/$fish_theme fish_function_path + _append_path $fish_custom/themes/$fish_theme fish_function_path end ### @@ -66,7 +58,9 @@ set user_function_path $fish_function_path[1] set -e fish_function_path[1] # Add all functions -set fish_function_path $fish_path/functions/ $fish_function_path +if not contains $fish_path/functions/ $fish_function_path + set fish_function_path $fish_path/functions/ $fish_function_path +end # Add all defined plugins for plugin in $fish_plugins diff --git a/plugins/django/djtest.fish b/plugins/django/djtest.fish index 9726130..ad07f23 100644 --- a/plugins/django/djtest.fish +++ b/plugins/django/djtest.fish @@ -9,5 +9,4 @@ function djtest else time python manage.py test $VERBOSE end - end diff --git a/plugins/emoji-clock/emoji-clock.fish b/plugins/emoji-clock/emoji-clock.fish index b41113f..05f7bc3 100644 --- a/plugins/emoji-clock/emoji-clock.fish +++ b/plugins/emoji-clock/emoji-clock.fish @@ -12,77 +12,77 @@ function emoji-clock set minutes (date '+%M') switch $hour case 01 - if test $minutes -ge 30 - set clock "🕜" - else - set clock "🕐" - end + if test $minutes -ge 30 + set clock "🕜" + else + set clock "🕐" + end case 02 - if test $minutes -ge 30 - set clock "🕝" - else - set clock "🕑" - end + if test $minutes -ge 30 + set clock "🕝" + else + set clock "🕑" + end case 03 - if test $minutes -ge 30 - set clock "🕞" - else - set clock "🕒" - end + if test $minutes -ge 30 + set clock "🕞" + else + set clock "🕒" + end case 04 - if test $minutes -ge 30 - set clock "🕟" - else - set clock "🕓" - end + if test $minutes -ge 30 + set clock "🕟" + else + set clock "🕓" + end case 05 - if test $minutes -ge 30 - set clock "🕠" - else - set clock "🕔" - end + if test $minutes -ge 30 + set clock "🕠" + else + set clock "🕔" + end case 06 - if test $minutes -ge 30 - set clock "🕡" - else - set clock "🕕" - end + if test $minutes -ge 30 + set clock "🕡" + else + set clock "🕕" + end case 07 - if test $minutes -ge 30 - set clock "🕢" - else - set clock "🕖" - end + if test $minutes -ge 30 + set clock "🕢" + else + set clock "🕖" + end case 08 - if test $minutes -ge 30 - set clock "🕣" - else - set clock "🕗" - end + if test $minutes -ge 30 + set clock "🕣" + else + set clock "🕗" + end case 09 - if test $minutes -ge 30 - set clock "🕤" - else - set clock "🕘" - end + if test $minutes -ge 30 + set clock "🕤" + else + set clock "🕘" + end case 10 - if test $minutes -ge 30 - set clock "🕥" - else - set clock "🕙" - end + if test $minutes -ge 30 + set clock "🕥" + else + set clock "🕙" + end case 11 - if test $minutes -ge 30 - set clock "🕦" - else - set clock "🕚" - end + if test $minutes -ge 30 + set clock "🕦" + else + set clock "🕚" + end case 12 - if test $minutes -ge 30 - set clock "🕧" - else - set clock "🕛" - end + if test $minutes -ge 30 + set clock "🕧" + else + set clock "🕛" + end case '*' set clock "⌛" end echo $clock diff --git a/plugins/gi/gi.load b/plugins/gi/gi.load index 0fa64ff..62d0784 100644 --- a/plugins/gi/gi.load +++ b/plugins/gi/gi.load @@ -1,20 +1,19 @@ # gitignore.io cli for fish -# function gi #curl http://gitignore.io/api/$argv - set -l params (echo $argv|tr ' ' ',') - curl http://gitignore.io/api/$params + set -l params (echo $argv|tr ' ' ',') + curl http://gitignore.io/api/$params end # enable the complation by invoking `gi list` if not set -q -g gi_list - timeout 2 ping -c 1 -q gitignore.io >/dev/null - set gi_available $status - - if test $gi_available - set -g gi_list (gi list| tr ',' ' ' ^/dev/null) - end + timeout 2 ping -c 1 -q gitignore.io >/dev/null + set gi_available $status + + if test $gi_available + set -g gi_list (gi list| tr ',' ' ' ^/dev/null) + end end -complete -c gi -a "$gi_list" \ No newline at end of file +complete -c gi -a "$gi_list" diff --git a/plugins/node/node.load b/plugins/node/node.load index 32af336..a72dec8 100644 --- a/plugins/node/node.load +++ b/plugins/node/node.load @@ -1,6 +1,4 @@ ### Main program -if test -d /usr/local/share/npm/bin - set PATH /usr/local/share/npm/bin $PATH -end +_append_path /usr/local/share/npm/bin set PATH ./node_modules/.bin $PATH diff --git a/plugins/php/phphttp.fish b/plugins/php/phphttp.fish index 21cbed2..bdf4a1d 100644 --- a/plugins/php/phphttp.fish +++ b/plugins/php/phphttp.fish @@ -1,87 +1,87 @@ # PHP HTTP server. function phphttp - set -l port 8000 - set -l path - set -l host 127.0.0.1 + set -l port 8000 + set -l path + set -l host 127.0.0.1 - # Ignore argument for slice. - set argv $argv ignore + # Ignore argument for slice. + set argv $argv ignore - # Process options. I think that fish should have some builtin for - # option parsing, but it doesn't. - while count $argv > /dev/null - set -l option $argv[1] + # Process options. I think that fish should have some builtin for + # option parsing, but it doesn't. + while count $argv > /dev/null + set -l option $argv[1] - switch $option - # When two hyphens appear, stop processing, while removing - # hyphens from $argv. - case -- - set argv $argv[2..-1] - break + switch $option + # When two hyphens appear, stop processing, while removing + # hyphens from $argv. + case -- + set argv $argv[2..-1] + break - # Public mode. - case -p\* --p --pu --pub --publ --publi --public p public - if test $host = 0 - echo phphttp: Duplicate option --public >&2 - end - set host 0 + # Public mode. + case -p\* --p --pu --pub --publ --publi --public p public + if test $host = 0 + echo phphttp: Duplicate option --public >&2 + end + set host 0 - # Help. - case -h\* --h --he --hel --help '-\?' h help - echo 'phphttp [--public] ' - return + # Help. + case -h\* --h --he --hel --help '-\?' h help + echo 'phphttp [--public] ' + return - # Anything else stops processing. - case \* - break - end - - # Check if the option was one letter. - switch $option - case --\* - # Doesn't count as single option - - case -\?\?\* - set argv[1] -(expr substr $argv[1] 3 length $argv[1]) - continue - end - - set argv $argv[2..-1] + # Anything else stops processing. + case \* + break end - if test (count $argv[1..-1]) -ge 4 - echo 'phphttp: Expected up to two arguments, got '(math (count $argv) - 1)'.' >&2 + # Check if the option was one letter. + switch $option + case --\* + # Doesn't count as single option + + case -\?\?\* + set argv[1] -(expr substr $argv[1] 3 length $argv[1]) + continue + end + + set argv $argv[2..-1] + end + + if test (count $argv[1..-1]) -ge 4 + echo 'phphttp: Expected up to two arguments, got '(math (count $argv) - 1)'.' >&2 + return + end + + # argv is bigger by 1 because of "ignore" argument. + if test (count $argv) -ge 2 + # Check legality of first argument + switch $argv[1] + # Fine values + case {0,1,2,3,4,5,6,7,8,9}\* + # Do nothing + + case \* + # The dev team thinks of everything. Or something. + if test -d $argv[1] + if test (count $argv) -eq 2 + echo "phphttp: directory specified without port." >&2 + else + echo "phphttp: swapped directory and port arguments." >&2 + end return + else + echo "phphttp: $argv[1] is not a port." >&2 + return + end end - # argv is bigger by 1 because of "ignore" argument. - if test (count $argv) -ge 2 - # Check legality of first argument - switch $argv[1] - # Fine values - case {0,1,2,3,4,5,6,7,8,9}\* - # Do nothing + set port $argv[1] + end + if test (count $argv) -eq 3 + set path -t$argv[2] + end - case \* - # The dev team thinks of everything. Or something. - if test -d $argv[1] - if test (count $argv) -eq 2 - echo "phphttp: directory specified without port." >&2 - else - echo "phphttp: swapped directory and port arguments." >&2 - end - return - else - echo "phphttp: $argv[1] is not a port." >&2 - return - end - end - - set port $argv[1] - end - if test (count $argv) -eq 3 - set path -t$argv[2] - end - - php -S$host:$port $path + php -S$host:$port $path end diff --git a/plugins/plenv/plenv.load b/plugins/plenv/plenv.load index d4c60c7..107b6bf 100644 --- a/plugins/plenv/plenv.load +++ b/plugins/plenv/plenv.load @@ -1,7 +1,2 @@ -if test -d $HOME/.plenv/bin - set PATH $HOME/.plenv/bin $PATH -end - -if test -d $HOME/.plenv/shims - set PATH $HOME/.plenv/shims $PATH -end +_append_path $HOME/.plenv/bin +_append_path $HOME/.plenv/shims diff --git a/plugins/pyenv/pyenv.load b/plugins/pyenv/pyenv.load index b48aa79..5d771f6 100644 --- a/plugins/pyenv/pyenv.load +++ b/plugins/pyenv/pyenv.load @@ -1,15 +1,7 @@ if test -n "$PYENV_ROOT" - if test -d $PYENV_ROOT/bin - set PATH $PYENV_ROOT/bin $PATH - end - if test -d $PYENV_ROOT/shims - set $PATH $PYENV_ROOT/shims $PATH - end + _append_path $PYENV_ROOT/bin + _append_path $PYENV_ROOT/shims else - if test -d $HOME/.pyenv/bin - set PATH $HOME/.pyenv/bin $PATH - end - if test -d $HOME/.pyenv/shims - set PATH $HOME/.pyenv/shims $PATH - end + _append_path $HOME/.pyenv/bin + _append_path $HOME/.pyenv/shims end diff --git a/plugins/python/python.load b/plugins/python/python.load index 7f2bbc2..d0eb8fe 100644 --- a/plugins/python/python.load +++ b/plugins/python/python.load @@ -1,4 +1,2 @@ -if test -d /usr/local/share/python - set PATH /usr/local/share/python $PATH -end +_append_path /usr/local/share/python diff --git a/plugins/rbenv/rbenv.load b/plugins/rbenv/rbenv.load index de49047..7becc30 100644 --- a/plugins/rbenv/rbenv.load +++ b/plugins/rbenv/rbenv.load @@ -1,17 +1,7 @@ if test -n "$RBENV_ROOT" - if test -d $RBENV_ROOT/bin - set PATH $RBENV_ROOT/bin $PATH - end - - if test -d $RBENV_ROOT/shims - set PATH $RBENV_ROOT/shims $PATH - end + _append_path $RBENV_ROOT/bin + _append_path $RBENV_ROOT/shims else - if test -d $HOME/.rbenv/bin - set PATH $HOME/.rbenv/bin $PATH - end - - if test -d $HOME/.rbenv/shims - set PATH $HOME/.rbenv/shims $PATH - end + _append_path $HOME/.rbenv/bin + _append_path $HOME/.rbenv/shims end diff --git a/plugins/z/z.fish b/plugins/z/z.fish index 24227fe..b138529 100644 --- a/plugins/z/z.fish +++ b/plugins/z/z.fish @@ -1,3 +1,3 @@ function z - cd (bash -c 'source /usr/local/etc/profile.d/z.sh; _z $0; echo $PWD' $argv) + cd (bash -c 'source $Z_SCRIPT_PATH; _z $0; echo $PWD' $argv) end diff --git a/plugins/z/z.load b/plugins/z/z.load index 63b4b0c..6872457 100644 --- a/plugins/z/z.load +++ b/plugins/z/z.load @@ -1,5 +1,9 @@ +if test -z "$Z_SCRIPT_PATH" + set -x Z_SCRIPT_PATH /usr/local/etc/profile.d/z.sh +end + function __check_z --on-variable PWD --description 'Setup z on directory change' status --is-command-substitution; and return - bash -c "source /usr/local/etc/profile.d/z.sh; _z --add `pwd -P`" + bash -c "source $Z_SCRIPT_PATH; _z --add `pwd -P`" end diff --git a/themes/gianu/README.md b/themes/gianu/README.md new file mode 100644 index 0000000..e898913 --- /dev/null +++ b/themes/gianu/README.md @@ -0,0 +1,14 @@ +## Gianu + +Original theme made by gianu for oh-my-zsh, converted to oh-my-fish by JBarberU + +![gianu theme](http://jbarber.se/images/gianu.png) + + +#### Characteristics + +Displays: + +* Username and hostname +* Working directory +* Git information when available. diff --git a/themes/gianu/fish_prompt.fish b/themes/gianu/fish_prompt.fish new file mode 100644 index 0000000..a9db1c5 --- /dev/null +++ b/themes/gianu/fish_prompt.fish @@ -0,0 +1,35 @@ +# name: Gianu +function _git_branch_name + echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||') +end + +function _is_git_dirty + echo (command git status -s --ignore-submodules=dirty ^/dev/null) +end + +function fish_prompt + set -l cyan (set_color cyan) + set -l yellow (set_color -o yellow) + set -l red (set_color -o red) + set -l green (set_color -o green) + set -l white (set_color -o white) + set -l normal (set_color normal) + + + set -l cwd $cyan(basename (prompt_pwd)) + + if [ (_git_branch_name) ] + set -l git_branch $green(_git_branch_name) + set git_info "$normal($green$git_branch" + + if [ (_is_git_dirty) ] + set -l dirty "$yellow ✗" + set git_info "$git_info$dirty" + end + + set git_info "$git_info$normal)" + end + + echo -n -s $normal '[' $white (whoami) $normal '@' $red (hostname -s) $normal ' ' $cwd ' ' $git_info $normal ']$ ' +end + diff --git a/themes/mtahmed/README.md b/themes/mtahmed/README.md new file mode 100644 index 0000000..1804775 --- /dev/null +++ b/themes/mtahmed/README.md @@ -0,0 +1,15 @@ +## mtahmed + +Minimal theme. + +![mtahmed theme](http://csclub.uwaterloo.ca/~mtahmed/media/images/fish.png) + +#### Left prompt + +- First 10 characters of hostname if `ssh`'ed +- Current directory name (not path) +- ─╼ (cute little unicode characters) + +#### Right prompt + +- Exit code of the previous command diff --git a/themes/mtahmed/fish_prompt.fish b/themes/mtahmed/fish_prompt.fish new file mode 100644 index 0000000..24afde8 --- /dev/null +++ b/themes/mtahmed/fish_prompt.fish @@ -0,0 +1,19 @@ +# name: mtahmed +# Left prompt: +# - First 10 characters of hostname if ssh'ed +# - Current directory name +# - ─╼ +# Right prompt: +# - Exit code of the previous command +function fish_prompt + set_color $fish_color_cwd + if [ -n "$SSH_CONNECTION" ] + printf '%s | ' (hostname | head -c 10) + end + if [ "$HOME" = (pwd) ] + printf "~" + else + printf (basename (pwd)) + end + printf " ─╼ " +end diff --git a/themes/mtahmed/fish_right_prompt.fish b/themes/mtahmed/fish_right_prompt.fish new file mode 100644 index 0000000..c8eb8b5 --- /dev/null +++ b/themes/mtahmed/fish_right_prompt.fish @@ -0,0 +1,12 @@ +# name: mtahmed +# Left prompt: +# - First 10 characters of hostname if ssh'ed +# - Current directory name +# - ─╼ +# Right prompt: +# - Exit code of the previous command +function fish_right_prompt + set -l last_status $status + set_color $fish_color_cwd + printf $last_status +end diff --git a/tools/install.sh b/tools/install.sh index 0565d01..f6e541f 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -7,7 +7,7 @@ then fi echo -e "\033[0;34mCloning Oh My Fish...\033[0m" -hash git >/dev/null && /usr/bin/env git clone git://github.com/bpinto/oh-my-fish.git ~/.oh-my-fish || { +hash git >/dev/null && /usr/bin/env git clone https://github.com/bpinto/oh-my-fish.git ~/.oh-my-fish || { echo -e "git not installed" exit }