Commit 64974603 authored by Bruno's avatar Bruno

Merge pull request #468 from bobthecow/subtree-split

Move all plugins and themes to oh-my-fish repos.
parents d3b40075 adb9caf2
if test -n "$ANDROID_SDK_ROOT"
_prepend_path $ANDROID_SDK_ROOT/tools
_prepend_path $ANDROID_SDK_ROOT/platform-tools
else
_prepend_path /opt/android-sdk/tools
_prepend_path /opt/android-sdk/platform-tools
end
# The Arch Linux Plugins
The Arch Linux Plugins provides a number of plugins to make using arch easier.
# The Plugins
## archlinux
This plugin includes all of provided Arch Linux Plugins wrapped in a single plugin.
To use this plugin append the following `archlinux` to `fish_plugins`.
## archlinux/pacman
This plugin makes working with pacman easier and faster. Please refer to pacman/README.md for more information.
To use this plugin append the following `archlinux/pacman` to `fish_plugins`.
set -l current_dir (dirname $argv)
# add pacman related functions
set fish_function_path $current_dir/pacman $fish_function_path
# pacman functions #
* pacin
Install specific package(s) from the repositories
* pacins
Install specific package not from the repositories but from a file
* pacre
Remove the specified package(s), retaining its configuration(s) and required dependencies
* pacrem
Remove the specified package(s), its configuration(s) and unneeded dependencies
* pacrep
Display information about a given package in the repositories
* pacreps
Search for package(s) in the repositories
* pacloc
Display information about a given package in the local database
* paclocs
Search for package(s) in the local database
* pacupd
Update and refresh the local package and ABS databases against repositories
* pacinsd
Install given package(s) as dependencies of another package
* pacmir
Force refresh of all package lists after updating /etc/pacman.d/mirrorlist
* paclist
List all installed packages with a short description - Source
* paclsorphans
List all orphaned packages
* pacrmorphans
Delete all orphaned packages
* pacdisowned | less +F
List all disowned files in your system
# Based on aliases from oh-my-zsh
Source: https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/archlinux/archlinux.plugin.zsh
function pacdisowned -d "Display list of disowned files"
if test -d "$TMPDIR"
set tmp $TMPDIR
else
set tmp "/tmp"
end
set dir (mktemp -d -p $tmp)
set -l fs "$dir/fs"
set -l db "$dir/db"
pacman -Qlq | sort -u > "$db"
find /bin /etc /lib /sbin /usr ! -name lost+found \
\( -type d -printf '%p/\n' -o -print \) | sort > "$fs"
comm -23 "$fs" "$db"
# clean-up after ourself
rm -rf "$dir"
end
function pacin -d "Install specific package(s) from the repositories"
sudo pacman -S $argv
end
function pacins -d "Install specific package not from the repositories but from a file"
sudo pacman -U $argv
end
function paclist
pacman -Qei (pacman -Qu|cut -d" " -f 1)|awk ' BEGIN {FS=":"}/^Name/{printf("\033[1;36m%s\033[1;37m", $2)}/^Description/{print $2}'
end
function pacloc -d "Display information about a given package in the local database"
pacman -Qi $argv
end
function paclocs -d "Search for package(s) in the local database"
pacman -Qs $argv
end
function paclsorphans -d "Display a list of packages that were installed as dependencies but are no longer required by any installed package"
pacman -Qdt $argv
end
function pacmanallkeys -d "Get all keys for developers and trusted users"
curl https://www.archlinux.org/developers/ https://www.archlinux.org/trustedusers/ | awk -F\" '(/pgp.mit.edu/) {sub(/.*search=0x/,"");print $1}' | xargs sudo pacman-key --recv-keys
end
function pacmansignkeys -d "Allow user to sign keys"
for key in $argv;
sudo pacman-key --recv-keys $key
sudo pacman-key --lsign-key $key
printf 'trust\n3\n' | sudo gpg --homedir /etc/pacman.d/gnupg \
--no-permission-warning --command-fd 0 --edit-key $key
end
end
function pacmir -d "Force refresh of all package lists after updating /etc/pacman.d/mirrorlist"
sudo pacman -Syy $argv
end
function pacre -d "Remove the specified package(s), retaining its configuration(s) and required dependencies"
sudo pacman -R $argv
end
function pacrem -d "Remove the specified package(s), its configuration(s) and unneeded dependencies"
sudo pacman -Rns $argv
end
function pacrep -d "Display information about a given package in the repositories"
pacman -Si $argv
end
function pacreps -d "Search for package(s) in the repositories"
pacman -Ss $argv
end
function pacrmorphans -d "Remove all real orphan packages"
sudo pacman -Rs (pacman -Qtdq) $argv
end
which abs ^ /dev/null > /dev/null
if test $status -ne 1
function pacupd -d "Update and refresh the local package and ABS databases against repositories"
sudo pacman -Sy; and sudo abs
end
else
function pacupd -d "Update and refresh the local package against repositories"
sudo pacman -Sy
end
end
function pacupg -d "Synchronize with repositories before upgrading packages that are out of date on the local system."
sudo pacman -Syu $argv
end
function __bak_help
echo -e \
"Usage:
$argv[1] SOURCE..."
end
function __bak_parse_help
if [ (count $argv) -lt 3 ]
__bak_help $argv[1]
else
return 1
end
end
function __bak_name
# trim / for directories
set file (echo $argv[1] | sed 's/\/*$//')
echo "$file."(date +'%Y%m%d_%H%M%S')".bak"
end
function __bak
__bak_parse_help $argv
or begin
set program $argv[2]
for file in $argv[3..-1]
eval $program $file (__bak_name $file)
end
end
end
set -g __bak_re '(.*)\.[0-9]{8,8}_[0-9]{6,6}\.bak\/*$'
function __is_bak
set file $argv[1]
echo "$file" | grep -Eq $__bak_re
end
function __bak_normalized
set file $argv[1]
echo "$file" | sed -E "s/$__bak_re/\1/g"
end
function __unbak
__bak_parse_help $argv
or begin
set program $argv[2]
for file in $argv[3..-1]
set normalized (__bak_normalized $file)
if test ! -e $file
echo "File \"$file\" not exists! Cannot unbak \"$file\"."
else if not __is_bak $file
echo "File \"$file\" don't meet bak files convention! Cannot unbak \"$file\"."
else if test -e $normalized
echo "File \"$normalized\" exists! Cannot unbak \"$file\"."
else
eval $program $file $normalized
end
end
end
end
# Function to copy files and directories (a.txt copy to a.txt.20140608_195859.bak)
# (c) Roman Inflianskas (rominf) <infroma@gmail.com>, 2014
function cpbak --description 'Copy files to make a backup copies'
__bak cpbak 'cp -a' $argv
end
# Function to rename files and directories (a.txt rename to a.txt.20140608_195859.bak)
# (c) Roman Inflianskas (rominf) <infroma@gmail.com>, 2014
function mvbak --description 'Rename files to make a backup copies'
__bak mvbak mv $argv
end
# Function to copy files and directories (a.txt.20140608_195859.bak copy to a.txt)
# (c) Roman Inflianskas (rominf) <infroma@gmail.com>, 2014
function uncpbak --description 'Copy files to revert a backup copies to a normal files'
__unbak uncpbak 'cp -a' $argv
end
# Function to move files and directories (a.txt.20140608_195859.bak move to a.txt)
# (c) Roman Inflianskas (rominf) <infroma@gmail.com>, 2014
function unmvbak --description 'Move files to revert a backup copies to a normal files'
__unbak unmvbak mv $argv
end
# A better alias provide completion
Use `balias` instead of `alias`,you can get same completion meanwhile you set alias.
# Example
```
balias apti 'sudo apt-get install'
balias gc 'git checkout'
```
Then,you will get
![apti](http://www.geekpics.net/images/2014/08/23/TJn6kfBY.png)
![gc](http://www.geekpics.net/images/2014/08/23/655x76xcPJolvxqra.png.pagespeed.ic.4S9hgPfZ53.png)
function balias --argument alias command
eval 'alias $alias $command'
if expr $command : '^sudo '>/dev/null
set command (echo "$command" | cut -c6-)
end
complete -c $alias -xa "(
set -l cmd (commandline -pc | sed -e 's/^ *\S\+ *//' );
complete -C\"$command \$cmd\";
)"
end
import plugins/fish-spec
import plugins/balias
function describe_library -d "balias: better-alias"
function after_all
functions -e changedir
functions -e ls_as_root
end
function it_doesnt_fail
balias changedir cd
expect $status --to-equal 0
end
function it_defines_an_alias
balias changedir cd
set -l ignore_output (functions changedir)
expect $status --to-equal 0
end
function you_can_use_the_alias
mkdir testdir
changedir testdir
expect test $status --to-be-true
cd ..
rmdir testdir
end
function it_chops_off_sudo
balias ls_as_root 'sudo ls'
expect test $status --to-be-true
end
end
spec.run $argv
set -l brew_paths /usr/local/bin /usr/bin /bin /usr/local/sbin /usr/sbin /sbin
# Append all existing brew paths to PATH
set -l existing_brew_paths
for brew_path in $brew_paths
if test -d $brew_path
set PATH $PATH $brew_path
set existing_brew_paths $existing_brew_paths $brew_path
end
end
# Remove brew paths from tail to head that were not recently added
set -l number_of_paths_to_ignore (math (count $PATH) - (count $existing_brew_paths))
for i in (seq (count $PATH))[-1..1]
if test $i -le $number_of_paths_to_ignore
if contains $PATH[$i] $brew_paths
set -e PATH[$i]
end
end
end
set -e brew_paths
set -e existing_brew_paths
set -e existing_brew_paths_count
# These methods override the default calls to append `bundle exec` if this gem
# is available within the context of bundler.
#
# You can add more bundled executables in your config.fish:
#
# set bundler_plugin_execs jekyll mustache
#
set -l execs annotate \
cap \
capify \
cucumber \
dashing \
foreman \
guard \
kitchen \
middleman \
nanoc \
puma \
rackup \
rainbows \
rake \
rspec \
rubocop \
ruby \
shotgun \
sidekiq \
spec \
spinach \
spork \
thin \
thor \
unicorn \
unicorn_rails
if set -q bundler_plugin_execs
set execs $execs $bundler_plugin_execs
end
# Fish 2.1.1+ has support for --inherit-variable
set -l do_eval (echo $FISH_VERSION | grep 2.1.1-)
for executable in $execs
if test -z "$do_eval"
eval "function $executable; __execute_as_bundler $executable \$argv; end"
else
function $executable --inherit-variable executable
__execute_as_bundler $executable $argv
end
end
end
function __execute_as_bundler
if __is_a_bundled_executable $argv[1]
command bundle exec $argv
else
eval command $argv
end
end
function __is_a_bundled_executable
set -l bindir (command bundle exec ruby -e 'puts Gem.bindir')
test -f "$bindir/$argv"
end
_prepend_path $HOME/.cask/bin
\ No newline at end of file
# Use ccache for building Android
# See: https://source.android.com/source/initializing.html#setting-up-ccache
set -gx USE_CCACHE 1
if test -n "$CCACHE_ROOT"
_prepend_path $CCACHE_ROOT
else
_prepend_path /usr/lib/ccache/bin
end
## chruby plugin
Depends on `chruby-fish`: https://github.com/JeanMertz/chruby-fish
set `CHRUBY_AUTO_ENABLED` to `false` to disable auto loading Ruby versions on
directory change.
set `CHRUBY_ROOT` to point to the root path of chruby. The path will be
appended by `share/chruby/chruby.fish` and `share/chruby/auto.fish`.
#
# Depends on `chruby-fish` (https://github.com/JeanMertz/chruby-fish)
#
# set `CHRUBY_AUTO_ENABLED` to `false` to disable auto loading Ruby versions on
# directory change.
#
# set `CHRUBY_ROOT` to point to the root path of chruby. The path will be
# appended by `share/chruby/chruby.fish` and `share/chruby/auto.fish`.
#
set -q CHRUBY_ROOT; or set CHRUBY_ROOT /usr/local
if test -f "$CHRUBY_ROOT/share/chruby/chruby.fish"
. "$CHRUBY_ROOT/share/chruby/chruby.fish"
else
echo '`chruby` plugin loaded but chruby-fish not installed.' \
'See: https://github.com/JeanMertz/chruby-fish'
end
if test "$CHRUBY_AUTO_ENABLED" != "false" -a \
-f "$CHRUBY_ROOT/share/chruby/auto.fish"
. "$CHRUBY_ROOT/share/chruby/auto.fish"
end
# composer command
function composer
if test -e ./composer.phar # if there is composer in this path use local one
./composer.phar $argv;
else if test -n "$COMPOSER_BIN"
eval "$COMPOSER_BIN" $argv;
else
echo "Please install composer.phar to your PATH. Or use \"composer_install\" to install Composer to current directory."
end
end
# add Composer's global binaries to PATH
if test -z "$COMPOSER_BIN_PATH"
set -gx COMPOSER_BIN_PATH $HOME/.composer/vendor/bin
end
set PATH $COMPOSER_BIN_PATH $PATH
# get composer path
if test -z "$COMPOSER_BIN"
if type "composer.phar" > /dev/null
set -gx COMPOSER_BIN (which composer.phar)
else if type "composer" > /dev/null
set -gx COMPOSER_BIN (which composer)
else
echo "FAILED to find Composer! Please install composer.phar to your PATH."
end
end
# install composer in the current directory
function composer_install
curl -s https://getcomposer.org/installer | php
end
# time, cleanup pyc and running test, settings as first argument
# e.g. djtest settings_dev
function djtest
set VERBOSE --verbosity=1
find . -name "*.pyc" -delete
if set -q argv
time python manage.py test $VERBOSE --settings=$argv
else
time python manage.py test $VERBOSE
end
end
The MIT License (MIT)
Copyright (c) 2014 Roman Inflianskas
Copyright (c) 2014 Paul Joannon (sprunge.fish)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#!/usr/bin/env fish
# vim: ai ts=2 sw=2 et sts=2
# Just a dpaste (https://github.com/bartTC/dpaste) wrapper for fish-shell
# Roman Inflianskas (rominf) <infroma@gmail.com>
# Based on fish-sprunge plugin:
# Paul Joannon (paulloz) <paul.joannon@gmail.com>
# https://github.com/Paulloz/fish-sprunge
# Based on oh-my-zsh's sprunge plugin
set __dpaste_expires_choises '(onetime|1|twotimes|2|hour|week|month|never)'
function __dpaste_set_defaults
set -g __dpaste_url_dpaste_de 'https://dpaste.de/api/?format=url'
set -g __dpaste_keyword_dpaste_de 'content'
set -g __dpaste_url_sprunge_us 'http://sprunge.us/'
set -g __dpaste_keyword_sprunge_us 'sprunge'
set -q dpaste_site; or set -g dpaste_site 'dpaste.de'
set suffix (echo $dpaste_site | sed "s/\./_/g")
set -g __dpaste_keyword (eval 'echo $__dpaste_keyword_'$suffix)
set -q __dpaste_keyword; or set -g __dpaste_keyword $__dpaste_keyword_dpaste_de
set -g __dpaste_send_url (eval 'echo $__dpaste_url_'$suffix)
set -q __dpaste_send_url; or set -g __dpaste_send_url $__dpaste_url_dpaste_de
set -g __dpaste_eat_once 0
end
function __dpaste_send
function curl
command curl --silent $argv
end
curl -F "$__dpaste_keyword=<-" $__dpaste_send_url | read -l url
if [ $__dpaste_eat_once = 1 ]
curl $url >/dev/null
end
echo $url
end
function __dpaste_parse_expires
set expires_spec "-t $__dpaste_expires_choises"
set expires (echo $argv | sed -E "s/.*$expires_spec.*/\1/")
if [ -z (echo $expires | sed -E "s/$__dpaste_expires_choises//") ]
echo $expires | grep -qE '(onetime|1)'; set -g __dpaste_eat_once (and echo 1; or echo 0)
set expires (echo $expires | sed -E 's/(1|2|twotimes)/onetime/;s/hour/3600/;s/week/604800/;s/month/2592000/')
set __dpaste_send_url "$__dpaste_send_url&expires=$expires"
end
echo $argv | sed -E "s/$expires_spec//" | xargs
end
function __dpaste_help
echo -e \
"Usage:
dpaste [-t EXPIRES] < README.md
dpaste [-t EXPIRES] README.md
cat README.md | dpaste [-t EXPIRES]
dpaste [-t EXPIRES] \"I \<3 to paste\"
Options:
-t EXPIRES set snippet expiration time: $__dpaste_expires_choises [default: month]
Configuration:
You can use this plugin with other dpaste instances.
If you have a dpaste instance on 'example.com' just insert those lines
into your config.fish file:
set __dpaste_url_example_com 'https://example.com/api/?format=url'
set dpaste_site 'example.com'
You can even use this plugin with sprunge.us.
Note, that sprunge.us doesn't support '-t' option.
set dpaste_site 'sprunge.us'"
end
function __dpaste_parse_help
begin
contains -- -h $argv
or contains -- --help $argv
end
and __dpaste_help
end
function dpaste
__dpaste_set_defaults
__dpaste_parse_help $argv
or begin
set argv (__dpaste_parse_expires $argv)
if isatty
if [ -n $argv ]
if [ -f $argv ]
cat $argv
else
echo $argv
end | __dpaste_send
else
__dpaste_help
end
else
__dpaste_send
end
end
end
set -l fish_tank /usr/local/share/fish-tank/tank.fish
if not test -e $fish_tank
echo 'error: fish-tank is required to run these tests (https://github.com/terlar/fish-tank)'
exit 1
end
source $fish_tank
#!/usr/bin/env fish
# vim: ai ts=2 sw=2 et sts=2
function echo_text
set -g __test_text 'Hello, tests! I am just testing suite for oh-my-fish plugin: https://github.com/bpinto/oh-my-fish/pull/170'
echo -e $__test_text
end
function curl
command curl --silent $argv
end
function curl_and_check
assert_equal $argv[2..-1] (curl $argv[1])
end
function curl_and_fail
assert_match '.*404 Not found.*' (curl $argv[1])
end
function test_dpaste_system
set url (eval $argv[1])/raw
curl_and_check $url (echo_text)
# now it shouldn't be available
curl_and_fail $url
end
function dpaste_setup
set -g test_dir /tmp/dpaste_test
set -g test_file $test_dir/file
mkdir -p $test_dir
pushd
cd $test_dir
echo_text > $test_file
end
function dpaste_teardown
rm -rf $test_dir
popd
end
function suite_dpaste
function setup
set dpaste_site 'dpaste.de'
__dpaste_set_defaults
end
function test_dpaste_parse_expires
assert_equal text (__dpaste_parse_expires text)
assert_equal "https://dpaste.de/api/?format=url" $__dpaste_send_url
end
function test_dpaste_parse_expires_1
assert_equal text (__dpaste_parse_expires -t 1 text)
assert_equal "https://dpaste.de/api/?format=url&expires=onetime" $__dpaste_send_url
end
function test_dpaste_parse_expires_hour
assert_equal text (__dpaste_parse_expires -t hour text)
assert_equal "https://dpaste.de/api/?format=url&expires=3600" $__dpaste_send_url
end
function test_dpaste_parse_expires_never
assert_equal text (__dpaste_parse_expires -t never text)
assert_equal "https://dpaste.de/api/?format=url&expires=never" $__dpaste_send_url
end
function test_dpaste_system_file_redirect
function dpaste_file_redirect
dpaste -t onetime < /tmp/dpaste_test/file
end
test_dpaste_system dpaste_file_redirect
end
function test_dpaste_system_file
function dpaste_file
dpaste -t onetime /tmp/dpaste_test/file
end
test_dpaste_system dpaste_file
end
function test_dpaste_system_stdin
function dpaste_stdin
echo_text | dpaste -t onetime
end
test_dpaste_system dpaste_stdin
end
function test_dpaste_system_text
function dpaste_text
dpaste -t onetime "$__test_text"
end
test_dpaste_system dpaste_text
end
end
if not set -q tank_running
source (dirname (status -f))/helper.fish
set -g __dpaste_expires_choises
source (dirname (status -f))/../dpaste.fish
dpaste_setup
tank_run
dpaste_teardown
end
### Main program
if test -d (/usr/libexec/java_home)
set -gx JAVA_HOME (/usr/libexec/java_home)
end
if test (/bin/ls $HOME/.ec2/pk-*.pem | /usr/bin/head -1)
set -gx EC2_PRIVATE_KEY (/bin/ls $HOME/.ec2/pk-*.pem | /usr/bin/head -1)
end
if test (/bin/ls $HOME/.ec2/cert-*.pem | /usr/bin/head -1)
set -gx EC2_CERT (/bin/ls $HOME/.ec2/cert-*.pem | /usr/bin/head -1)
end
if test -d /usr/local/Library/LinkedKegs/ec2-api-tools/jars
set -gx EC2_HOME /usr/local/Library/LinkedKegs/ec2-api-tools/jars
end
# Emacs Plugin
This plugin replicates the functionality of the [emacs](https://www.gnu.org/software/emacs/) plugin for [oh-my-zsh](http://ohmyz.sh/).
It is essentially a wrapper around the very useful [emacs daemon](http://www.emacswiki.org/emacs/EmacsAsDaemon) capability.
Below is an extract from the original plugin source file:
"Emacs 23 daemon capability is a killing feature.
One emacs process handles all your frames whether
you use a frame opened in a terminal via a ssh connection or X frames
opened on the same host.
Benefits are multiple
* You don't have the cost of starting Emacs all the time anymore
* Opening a file is as fast as Emacs does not have anything else to do.
* You can share opened buffered across opened frames.
* Configuration changes made at runtime are applied to all frames."
### Usage
To use this plugin add `emacs` to `fish_plugins` in you fish config file:
```bash
set fish_plugins emacs
```
### Requirements
Emacs 23 or later is required for this plugin.
\ No newline at end of file
function __major_version
if test -n "$argv"
set -l full_metadata (eval $argv --version)
set -l full_version (echo $full_metadata | grep -o "[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+")
set -l major_version (echo $full_version | sed "s/\..*//")
end
echo $major_version
end
function __set_editor
if not set -q EDITOR
set -gx EDITOR emacs
end
end
function __add_functions_to_path
set emacs_functions $fish_path/plugins/emacs/functions
set fish_function_path $emacs_functions $fish_function_path
end
if not set -q __emacs
set __emacs (which emacs)
end
if not set -q __emacs_version
set __emacs_version (__major_version $__emacs)
end
if test "$__emacs_version" -gt 23
__set_editor
__add_functions_to_path
end
set -e emacs
set -e emacs_version
functions -e __major_version
functions -e __plugins_path
functions -e __set_editor
functions -e __add_functions_to_path
function __kill_emacs
emacsclient --alternate-editor '' --eval '(kill-emacs)' 2>/dev/null
end
function __launch_emacs
set -l x (emacsclient --alternate-editor '' --eval '(x-display-list)' 2>/dev/null)
if test -z "$x" -o "$x" = nil
emacsclient $argv --alternate-editor '' --create-frame
else
emacsclient $argv --alternate-editor ''
end
end
function e
__launch_emacs $argv --no-wait
end
function ec
__launch_emacs $argv --create-frame --no-wait
end
function ecd
set -l cmd '(let ((buf-name (buffer-file-name (window-buffer))))
(if buf-name (file-name-directory buf-name)))'
set -l dir (__launch_emacs --eval $cmd | tr -d '\"')
if test -n "$dir"
echo $dir
else
echo 'cannot deduce current buffer filename.' >/dev/stderr
end
end
function eeval
__launch_emacs --eval $argv
end
function efile
set -l cmd '(buffer-file-name (window-buffer))'
__launch_emacs --eval $cmd | tr -d '\"'
end
function eframe
__launch_emacs $argv --create-frame --no-wait
end
function ek
__kill_emacs
end
function emacs
__launch_emacs $argv --no-wait
end
function emasc
__launch_emacs $argv --no-wait
end
function emcas
__launch_emacs $argv --no-wait
end
function et
__launch_emacs $argv --tty
end
import plugins/fish-spec
function describe_emacs
function before_all
set -g __emacs_current_editor $EDITOR
set -g __emacs_load_file $fish_path/plugins/emacs/emacs.load
set -g __emacs_functions e ec ek et ecd eeval efile eframe emacs emasc emcas
end
function before_each
set -e EDITOR
set -g __emacs '/bin/emacs'
set -g __emacs_version 25
end
function it_sets_editor_on_load
load_emacs_plugin
expect $EDITOR --to-equal "emacs"
end
function it_does_not_set_editor_when_it_is_already_set
set EDITOR 'vim'
load_emacs_plugin
expect $EDITOR --to-equal "vim"
end
function it_does_not_set_editor_when_emacs_is_not_found
emacs_is_not_found
load_emacs_plugin
expect "$EDITOR" --to-equal ""
end
function it_does_not_set_editor_when_emacs_version_is_lower_than_23
set __emacs_version 22
load_emacs_plugin
expect "$EDITOR" --to-equal ""
end
function it_adds_functions_to_fish_function_path
load_emacs_plugin
expect (functions) --to-contain-all $__emacs_functions
end
function it_has_a_test_helper_that_removes_emacs_functions
load_emacs_plugin
expect (functions) --to-contain-all $__emacs_functions
remove_emacs_functions
expect (functions) --to-not-contain-all $__emacs_functions
end
function it_does_not_add_functions_when_emacs_is_not_found
remove_emacs_functions
emacs_is_not_found
load_emacs_plugin
expect (functions) --to-not-contain-all $__emacs_functions
end
function it_does_not_add_functions_when_emacs_version_is_lower_than_23
set __emacs_version 22
expect (functions) --to-not-contain-all $__emacs_functions
load_emacs_plugin
expect (functions) --to-not-contain-all $__emacs_functions
end
function emacs_is_not_found
set __emacs ""
set __emacs_version ""
end
function load_emacs_plugin
source $__emacs_load_file
end
function remove_emacs_functions
for path in $fish_function_path
set match (echo $path | grep emacs)
if test -z "$match"
set -g __new_fish_function_path $__new_fish_function_path $path
end
end
set fish_function_path $__new_fish_function_path
set -e __new_fish_function_path
end
function after_all
set EDITOR $__emacs_current_editor
set -e __emacs
set -e __emacs_version
set -e __emacs_load_file
set -e __emacs_functions
set -e __emacs_current_editor
end
end
spec.run $argv
# ------------------------------------------------------------------------------
# FILE: emoji-clock.plugin.zsh
# DESCRIPTION: The current time with half hour accuracy as an emoji symbol.
# Inspired by Andre Torrez' "Put A Burger In Your Shell"
# http://notes.torrez.org/2013/04/put-a-burger-in-your-shell.html
# AUTHOR: Alexis Hildebrandt (afh[at]surryhill.net) ported to fish by Erik Kallen
# VERSION: 1.0.0
# -----------------------------------------------------------------------------
function emoji-clock
set hour (date '+%I')
set minutes (date '+%M')
switch $hour
case 01
if test $minutes -ge 30
set clock "🕜"
else
set clock "🕐"
end
case 02
if test $minutes -ge 30
set clock "🕝"
else
set clock "🕑"
end
case 03
if test $minutes -ge 30
set clock "🕞"
else
set clock "🕒"
end
case 04
if test $minutes -ge 30
set clock "🕟"
else
set clock "🕓"
end
case 05
if test $minutes -ge 30
set clock "🕠"
else
set clock "🕔"
end
case 06
if test $minutes -ge 30
set clock "🕡"
else
set clock "🕕"
end
case 07
if test $minutes -ge 30
set clock "🕢"
else
set clock "🕖"
end
case 08
if test $minutes -ge 30
set clock "🕣"
else
set clock "🕗"
end
case 09
if test $minutes -ge 30
set clock "🕤"
else
set clock "🕘"
end
case 10
if test $minutes -ge 30
set clock "🕥"
else
set clock "🕙"
end
case 11
if test $minutes -ge 30
set clock "🕦"
else
set clock "🕚"
end
case 12
if test $minutes -ge 30
set clock "🕧"
else
set clock "🕛"
end
case '*' set clock "⌛"
end
echo $clock
end
function export
set var1 (echo $argv | cut -f1 -d=)
set var2 (echo $argv | cut -f2 -d=)
set -x -g $var1 $var2
end
# Taken from: https://github.com/dideler/dotfiles/blob/master/functions/extract.fish
function extract --description "Expand or extract bundled & compressed files"
set --local ext (echo $argv[1] | awk -F. '{print $NF}')
switch $ext
case tar # non-compressed, just bundled
tar -xvf $argv[1]
case gz
if test (echo $argv[1] | awk -F. '{print $(NF-1)}') = tar # tar bundle compressed with gzip
tar -zxvf $argv[1]
else # single gzip
gunzip $argv[1]
end
case tgz # same as tar.gz
tar -zxvf $argv[1]
case bz2 # tar compressed with bzip2
tar -jxvf $argv[1]
case rar
unrar x $argv[1]
case zip
unzip $argv[1]
case '*'
echo "unknown extension"
end
end
### Main program
if test -d /usr/local/share/fry/fry.fish
. /usr/local/share/fry/fry.fish
end
# gem
Ruby gem support for fish.
## Install
Add `gem` to your list of fish plugins in your `config.fish`.
Example:
set fish_plugins gem bundler
## Configuration
Set `GEM_ROOT` in your `config.fish`.
Example:
set GEM_ROOT ~/.gem/ruby/2.1.0
if test -n "$GEM_ROOT"
set -gx GEM_HOME $GEM_ROOT
_prepend_path $GEM_ROOT/bin
end
# getopts
> friendly [`getopts`](http://en.wikipedia.org/wiki/Getopts) for [fish](https://fishshell.com) :fish:
## Usage
```fish
Add `getopts` to your `$fish_plugins` or import directly into your library via `import plugins/getopts`.
```
## Premise
Every utility / function needs to handle arguments. What usually happens is that every function does all the grunt work to parse `$argv` itself, and while some patterns do tend to recur, it's different almost every time. Enter fish `getopts`.
## Synopsis
`getopts <option string> [ARGV...]`
## Options
#### `<option string> [:][<letter>][[:]<word>[:[^]]]`
A string containing the option characters recognized by the utility calling `getopts`. If a `<letter>` or `<word>` ends in `:`, the option is expected to have an argument, which may be supplied separately or next to the option without spaces in the same string.
To indicate long options: `<letter>:<word>` and `<word>` are both valid option strings that will attempt to match `-<letter>` and `--<word>`.
To indicate _only_ short options, do not specify a `:<word>` after `<letter>`. For example, `a b` will match `-a` or `-b`.
To indicate optional arguments, use a `^` character after a `:` at the end of the option in the option string. For example `<letter>:^` and `<letter>:<word>:^` are both valid. Optional arguments should be supplied in the same string as the option and without spaces, e.g, `-<letter>value` will correctly assign `value` as the argument to the the option `<letter>`, but `-<letter>` value, will parse `value` as the next argument in `<ARGV>`.
To specify optional arguments using the option's long form, use a `=` character after the option: `--<word>=value`.
Use a `:` at the beginning of the option string to enable strict mode. If enabled, `getopts` will exit with a status __> 0__ if or when an unknown option is found. See [Diagnostics](#diagnostics).
#### `<ARGV>`
List of options and operands to parse. `getopts` prints any matched options as well as available argument separated by a \n to stdout and returns with a status of __0__ if there are still arguments; else returns with a status __> 0__ if the end of the options is reached or an error occurs. See [Diagnostics](#diagnostics).
#### Summary
| Option String | Argument | Short Style | Long Style |
|:---------------:|:--------------:|------------------|:--------------------:|
`"q:qqq:"` | Required | `-q1` `-q 1` | `--qqq 1` |
`"q:qqq:^"` | Optional | `-q1` | `--qqq=3` |
## Description
`getopts` obtains options and their arguments from a list of parameters that, as indicated by <option string>, are single letters preceded by a `-` or words preceded by `--` and possibly followed by an argument value.
fish `getopts` follows the specifications described in the [Utility Syntax Guidelines](http://pubs.opengroup.org/onlinepubs/7908799/xbd/utilconv.html). The following is a summary of the features:
+ Short options; single letters preceded by `-`, and long options; words preceded by `--`, are both supported.
+ Single letters may be grouped. `-abc``-a -b -c`
+ Options required to take an argument can specify the argument either in the same string as the option or separated from the by a space. (1) `-a argument`, (2) `-aargument`
+ Options that can take an argument optionally shall specify the argument in the same string as the option argument if in short option style: `-aargument`, or separated by a `=` if in long form: `--long-form=argument`. If a blank space is used, the following argument will be treated independently.
+ Options can appear multiple times in the same argument list. `getopts` will print every match sequentally on each call, and should default to the short form of the option if available.
+ The option delimiter `:` and optional argument character `^` shall not be used as an option.
+ `getopts` will return the remaining operands when the end of the options is reached, i.e, a `--` argument that is not an option is found, or an argument that does not begin with `-` is found.
## Environment Variables
The following environment variables are used internally by `getopts`. These variables are erased from memory when the function returns 1.
+ `__getopts_optstr` _Whitespace trimmed option string._
+ `__getopts_argv` _Preprocessed copy of arguments._
+ `__getopts_index` _Index of the next argument to handle._
+ `__getopts_required` _List of options with required arguments._
+ `__getopts_optional` _List of options with optional arguments._
## <a name="diagnostics"></a>Diagnostics
Possible exit status values are:
+ __0__: An argument formed like an option was found. This causes getopts to print the option short-style and its argument if avaiable. If strict-mode is enabled setting the first character of the option to `:`, an unknown option will cause `getopts` to fail. See below.
+ __1__: The end of the options was reached. Remaining operands are also sent to stdout.
+ __2__: An option argument was missing.
+ __3__: An unknown option was found. Only if strict-mode is enabled.
## Examples
```fish
function my_utility
while set optarg (getopts "l:long x: o:optional:^" $argv)
switch $optarg[1]
case l
echo handle `-l --long`
case x
echo handle `-x` w/ argument `$optarg[2]`
case o
echo handle `-o --optional` w/ optional argument `$optarg[2]`
case \*
echo unknown option `$optarg[1]`
end
end
echo -n operands: "`$optarg`"
end
```
## Links
+ [UNIX Utility Conventions](http://pubs.opengroup.org/onlinepubs/7908799/xbd/utilconv.html)
## License
[MIT](http://opensource.org/licenses/MIT) © [Jorge Bucaran](http://bucaran.me)
# NAME
# getopts -- getopts for fish
#
# SYNOPSIS
# getopts <option string> [ARGV...]
#
# OPTIONS
# <option string> [:][<letter>][[:]<word>[:[^]]]
#
# A string containing the option characters recognized by the utility
# calling getopts. If a <letter> or <word> ends in `:`, the option is
# expected to have an argument, which may be supplied separately or
# next to the option without spaces in the same string.
#
# To indicate long options: <letter>:<word> and <word> are both valid
# option strings that will attempt to match -<letter> and --<word>.
#
# For only short options, do not specify a :<word> after <letter>.
# For example, `a b` will match `-a` and/or `-b`.
#
# To indicate optional arguments, use a `^` character after a `:` at
# the end of the option in the option string. For example <letter>:^
# and <letter>:<word>:^ are both valid. Optional arguments should be
# supplied in the same string as the option and without spaces, e.g,
# -<letter>value will correctly assign `value` as the argument to the
# the option <letter>, but -<letter> value, will parse `value` as the
# next argument in <argv>.
#
# To specify optional arguments using the option's long form, use a
# `=` character after the option: --<word>=value.
#
# Use a `:` at the beginning of the option string to enable strict
# mode. If enabled, getopts will exit with a status > 0 if or when
# an unknown option is found. See DIAGNOSTICS.
#
# <ARGV>
#
# List of options and operands to parse. getopts prints any matched
# options as well as available argument separated by a \n to stdout
# and returns with a status of 0 if there are still arguments; else
# returns with a status > 0 if the end of the options is reached or
# an error occurs. See DIAGNOSTICS.
#
# DESCRIPTION
# getopts obtains options and their arguments from a list of parameters
# that, as indicated by <option string>, are single letters preceded by
# a - or words preceded by -- and possibly followed by an argument value.
#
# fish getopts follows the specifications described in the Utility Syntax
# Guidelines (see LINKS); the following is a summary of the features:
#
# + Short options; single letters preceded by -, and long options;
# words preceded by --, are both supported.
#
# + Single letters may be grouped. -abc → -a -b -c
#
# + Options required to take an argument can specify the argument
# either in the same string as the option or separated from the
# by a space. (1) -a argument, (2) -aargument
#
# + Options that can take an argument optionally shall specify the
# argument in the same string as the option argument if in short
# option style: -aargument, or separated by a = if in long form:
# --long-form=argument. If a blank space is used, the following
# argument will be treated independently.
#
# + Options can appear multiple times in the same argument list.
# getopts will print every match sequentally on each call, and
# should default to the short form of the option if available.
#
# + The option delimiter `:` and optional argument character `^`
# shall not be used as an option.
#
# + getopts will return the remaining operands when the end of the
# options is reached, i.e, a `--` argument that is not an option
# is found, or an argument that does not begin with `-` is found.
#
# ENVIRONMENT VARIABLES
# The following environment variables are used internally by getopts.
# These variables are erased from memory when the functions returns 1.
#
# + __getopts_optstr Whitespace trimmed option string.
# + __getopts_argv Preprocessed copy of arguments.
# + __getopts_index Index of the next argument to handle.
# + __getopts_required List of options with required arguments.
# + __getopts_optional List of options with optional arguments.
#
# DIAGNOSTICS
# Possible exit status values are:
#
# 0 An argument formed like an option was found. This causes getopts
# to print the option short-style and its argument if avaiable. If
# strict-mode is enabled setting the first character of the option
# to `:`, an unknown option will cause getopts to fail. See below.
#
# 1 The end of the options was reached. Remaining operands are also
# sent to stdout.
#
# 2 An option argument was missing.
#
# 3 An unknown option was found. Only if strict-mode is enabled.
#
# EXAMPLES
# function my_utility
# while set optarg (getopts "l:long x: o:optional:^" $argv)
# switch $optarg[1]
# case l
# echo handle `-l --long`
# case x
# echo handle `-x` w/ argument `$optarg[2]`
# case o
# echo handle `-o --optional` w/ optional argument `$optarg[2]`
# case \*
# echo unknown option `$optarg[1]`
# end
# end
# echo -n operands: "`$optarg`"
# end
#
# LINKS
# UNIX Utility Conventions
# → http://pubs.opengroup.org/onlinepubs/7908799/xbd/utilconv.html
#
# AUTHORS
# Jorge Bucaran <jbucaran@me.com>
#/
function getopts
# Currently supported return success/error conditions.
set -l __CONTINUE 0
set -l __END_OF_OPTIONS 1
set -l __OPTION_ARGUMENT_EXPECTED 2
set -l __UNKNOWN_OPTION_FOUND 3
# Self-destroying global variable cleanup utility.
# Should be called before returning 1.
function __getopts_cleanup
set -e __getopts_optstr
set -e __getopts_argv
set -e __getopts_index
set -e __getopts_required
set -e __getopts_optional
set -e __getopts_strict_mode
functions -e __getopts_increase_index
end
function __getopts_increase_index
set __getopts_index (math $__getopts_index + 1)
end
# Options string pre-processing.
if not set -q __getopts_optstr
set -g __getopts_optstr $argv[1]
set -e argv[1]
# Trim option string and collect required / optional options.
if [ -n "$__getopts_optstr" ]
set __getopts_optstr (printf $__getopts_optstr | tr -s '[:space:]' \n)
# Setting the first token of the option string to `:` enables
# strict mode. This causes getopts to abort the process if an
# unknown option is found.
set -l first_token (printf $__getopts_optstr | head -c1)
if [ : = "$first_token" ]
set -g __getopts_strict_mode --true
# We can safely remove the `:` character now.
set __getopts_optstr[1] (printf $__getopts_optstr[1] | cut -c2-)
end
# Collect options with optional and required option-arguments.
function __getopts_collect_optargs
for string in (printf "%s\n" $__getopts_optstr)
set -l token (printf $string | tail -c1)
set -l split_string (printf "%s\n" $string | tr : \n)
# Erase last to make sure not to append `^` token.
switch $token
case :
set -g __getopts_required $__getopts_required $split_string
set -e __getopts_required[-1]
case \^
set -g __getopts_optional $__getopts_optional $split_string
set -e __getopts_optional[-1]
end
end
functions -e __getopts_collect_optargs
end
__getopts_collect_optargs
end
end
# Sanitize arguments. Break up flags: -abc → -a -b -c, but skip optional
# arguments. If -w is a flag that can take an optional argument, -abw123
# should be parsed to → -a -b -w 123.
if not set -q __getopts_argv
function __getopts_sanitize_argv
for token in $argv
switch $token
case --\* # Skip!
case -\*
# Split each token into single characters with `.`
for char in (printf "%s" $token | cut -c2- | grep --only-matching .)
# Do not split short option characters if this option can
# take optional required arguments.
if [ -z "$suspend_break" ]
printf "-%s\n" $char
else
printf "%s" $char
end
# Suspend option break-up if the current option is either
# a required or an optional option type.
contains -- $char $__getopts_required $__getopts_optional
and set suspend_break --true
set last_char $char
end
# Break options if we were in suspend mode and reset flag.
# This makes sure to add a blank space if no argument was
# specified for the optional option-argument, but not for
# the required option-argument.
if [ -n "$suspend_break" ]
not contains -- $last_char $__getopts_required
and printf "\n"
set suspend_break ""
end
continue
end
printf "%s\n" $token
end
functions -e __getopts_sanitize_argv
end
set -g __getopts_argv (__getopts_sanitize_argv $argv)
end
# Always use our preprocessed argument list.
set argv $__getopts_argv
if not set -q __getopts_index
set -g __getopts_index 1
end
# Handle next argument as indicated by the current index.
if set -q argv[$__getopts_index]
set -l option $argv[$__getopts_index]
# Potential matches for $option are: (1) end of arguments `--`,
# (2) long/short options --* or -* or (3) begin of operands, if
# (1) and (2) fail.
switch $option
# End of arguments. Assume everything from this point are operands.
case --
set -e argv[1..$__getopts_index]
printf "%s\n" $argv
__getopts_cleanup
return $__END_OF_OPTIONS
# Looks like we have a well-formed long/short option. Parse.
case --\* -\*
# It will be useful later to know if the current option is in long
# style. Notice we add a leading blank, because cut fails when the
# first character is a dash `-`.
set -e is_long_option
test (printf " "$option | cut -c2-3) = "--"
and set -l is_long_option
# Trim leading dashes and prepare to match with valid options.
set option (printf "%s" $option | sed 's/^-*//g')
for substring in $__getopts_optstr
# Split up by token separator `:`. The resulting list contains
# all valid options, both in short and long style.
set -l tokens (printf $substring | tr : \n)
# Start last to first to avoid mistaking long w/ short options.
for index in (seq (count $tokens) -1 1)
set -l last_token (printf $substring | tail -c1)
# Find options with optional argument in long-style and
# try to split by required delimiter `=`
# Note: Optional values shall be separated from options in
# long style by an equals sign. See documentation.
if [ $last_token = \^ ]
if set -q is_long_option
set -l option_value (printf "%s" $option | tr = \n)
if set -q option_value[2]
# Check if it is a valid option match.
if [ $option_value[1] = $tokens[$index] ]
printf "%s\n" $tokens[1]
printf $option_value[2]
__getopts_increase_index
return $__CONTINUE
end
end
end
end
# We are already inside a possible short/long option match.
# Option is the argument in __getopts_argv[__getopts_index]
# The following compares option against each valid argument
# in the option string __getopts_optstr. If no match can be
# found, print the argument after the loop.
switch $option
case $tokens[$index]
# Success. Send first token to stdout to make sure short
# options, if available, always get the highest priority.
printf "%s\n" $tokens[1]
switch $last_token
# At this point, both required and optional arguments
# look the same to the parser, so we match last_token
# to either `:` required or `^` optional tokens. This
# is the result of preprocessing __getopts_argv.
case : \^
# Find options with optional argument in long-style.
if [ $last_token = \^ ]
if set -q is_long_option
# An optional argument in long-style here means it
# didn't split by = in previous checks, so we can
# handle it as a missing argument option and exit.
# Print any non-empty list character.
printf "\n"
__getopts_increase_index
return $__CONTINUE
end
end
# If we reach this, we are either handling a required
# option or an optional in short-style form. Both are
# seen by the parser the same after preprocessing.
# For example:
# Given the option string `a b:^`, -abX → -a -b X
# We need to peek at the next option
__getopts_increase_index
# Check if next argument exists.
if set -q argv[$__getopts_index]
# Sanitize the option-argument.
set -l value (printf "%s" $argv[$__getopts_index])
if [ -z "$value" ]
# Print any non-empty list character.
printf "\n"
else
printf $value
end
__getopts_increase_index
return $__CONTINUE
else
__getopts_cleanup
return $__OPTION_ARGUMENT_EXPECTED
end
# Option was a flag that takes no arguments.
case \*
__getopts_increase_index
return $__CONTINUE
end
end
end
end
# No match found. Print unknown option to stdout first, and
# if strict mode is enabled, abort, else continue.
printf $option
__getopts_increase_index
# If the first character of the option string is a `:`, this
# enables strict mode and any unknown options will cause the
# process to return > 0.
if set -q __getopts_strict_mode
__getopts_cleanup
return $__UNKNOWN_OPTION_FOUND
else
return $__CONTINUE
end
# Looks like we run out of options. Print operands return.
case \*
if [ $__getopts_index -gt 1 ]
# Sans the current index, get rid of everything up to here.
set -e argv[1..(math $__getopts_index-1)]
end
printf "%s\n" $argv
__getopts_cleanup
return $__END_OF_OPTIONS
end
else
# End of arguments, cleanup and exit.
__getopts_cleanup
return $__END_OF_OPTIONS
end
end
import plugins/fish-spec
import plugins/getopts
function describe_getotps -d "fish getopts"
function __getopts
set -l options $argv[1]
set -e argv[1]
while set option (getopts $options $argv)
if [ (count $option) -gt 1 ] # w/ argument
set result "$result$option[1]($option[2])"
else
set result "$result$option"
end
end
printf "$result$option"
end
function it_returns_1_if_empty
getopts
expect $status --to-equal 1
end
function it_handles_a_single_short_option
expect (__getopts "a" -a) --to-equal a
end
function it_handles_a_single_long_option
expect (__getopts "aa" --aa) --to-equal aa
end
function it_handles_short_options
set -l options "a b c x y z"
set -l expected abcxyz
expect (__getopts $options -abc -xyz) --to-equal $expected
and expect (__getopts $options -a -b -c -x -y -z) --to-equal $expected
end
function it_handles_long_options
expect (__getopts "x-rays ye zombie" --ye --zombie --x-rays) \
--to-equal yezombiex-rays
end
function it_handles_long_options_only
expect (__getopts "all blink crunch" --all --blink --crunch) \
--to-equal allblinkcrunch
end
function it_handles_all_options
expect (__getopts "g:get p:put u:update d:delete t:post" -tud --put --get) \
--to-equal tudpg
end
function it_handles_operands
expect (__getopts "" 1 2 3 4 5) --to-equal "1 2 3 4 5"
end
function it_handles_options_and_operands
expect (__getopts "g:get p:put u:update d:delete t:post" \
-ud --put --get --post url1 url2 user:password) \
--to-equal "udpgturl1 url2 user:password"
end
function it_handles_end_of_args_separator
expect (__getopts "a b c d" -abcd -- -x -y -z) --to-equal "abcd-x -y -z"
end
function it_detects_end_of_args
expect (__getopts "a b c" -abc 1 2 3 -x) --to-equal "abc1 2 3 -x"
end
function it_returns_unknown_option_error_on_strict_mode
while set option (getopts ":a b c d e f" -abcXdef 1 2 3)
set result "$result$option"
end
expect $status --to-equal 3
end
function it_handles_valid_options_while_on_strict_mode
while set option (getopts ":a b c d e f" -fed -cba 1 2 3)
set result "$result$option"
end
expect "$result" --to-equal fedcba
and expect "$option" --to-equal "1 2 3"
end
function it_returns_argument_missing_error_if_argument_is_missing
while set option (getopts "x y z:" -xy -z)
end
expect $status --to-equal 2
end
function it_handles_options_normally_until_an_error_is_found
while set option (getopts ":a b c d e f" -abcXdef 1 2 3)
set result "$result$option"
end
expect "$result" --to-equal abc
expect "$option" --to-equal X
end
function it_handles_short_options_separated_by_blanks
expect (__getopts "a: b: c:" -a '1st arg' -b '2nd arg' -c '3rd arg') \
--to-equal "a(1st arg)b(2nd arg)c(3rd arg)"
end
function it_handles_a_short_option_w_required_argument_without_space_separation
expect (__getopts "a: b:" -adarwin -blinux) --to-equal "a(darwin)b(linux)"
end
function it_handles_a_short_option_w_optional_argument_with_space_separation
expect (__getopts "a: b:^" -a darwin -b linux) --to-equal "a(darwin)b()linux"
end
function it_handles_options_w_argument
set -l url "http://github.com"
set -l expected "pg($url)"
set -l options "g:get: p:put"
expect (__getopts $options -pg$url) --to-equal $expected
and expect (__getopts $options -p --get $url) --to-equal $expected
end
function it_handles_options_w_optional_argument
set -l url "http://github.com"
set -l expected "pg($url)"
set -l options "g:get:^ p:put"
expect (__getopts $options -pg$url) --to-equal $expected
and expect (__getopts $options -p --get=$url) --to-equal $expected
and expect (__getopts $options -pg) --to-equal "pg()"
end
function it_handles_a_contrived_example
set -l options "A b c: x y z: long long-req: long-opt:^"
set -l args -xyz777 -Abc100 --long --long-req 32 --long-opt=!!! D O N E
expect (__getopts $options $args) --to-equal \
"xyz(777)Abc(100)longlong-req(32)long-opt(!!!)D O N E"
end
function it_handles_multiline_option_strings
set -l multiline_options "a:aaa
b:bbb
c:ccc
d:ddd"
expect (__getopts $multiline_options -dcbabcd) --to-equal "dcbabcd"
end
end
spec.run $argv
gitignore (gi) plugin
=====================
This plugin provides a simple command line interface to gitignore.io - a
website that generates .gitignore files based on your project requirements.
## Completions
The first step is to download the latest language list from gitignore.io so
that the fish completions can be updated. Run `gi update-completions` to
download the completions, they will be stored in
`~/.config/fish/completions/gi.fish`
You should repeat this occasionally to keep up to date.
## Usage
Type `gi` followed by TAB to view the list of languages available. To generate
a .gitignore file, specify the list of languages you are interested in and pipe
the output into the destination file. Example for a go-lang project:
gi go tags vagrant > .gitignore
git add .gitignore
function _update_gi_completions -d "Update completions for gitignore.io"
set compl_dir ~/.config/fish/completions
set compl_file "$compl_dir/gi.fish"
# Download list of ignore types
set -l gi_list (gi list | tr ',' ' ')
if test -z $gi_list
echo "No result returned from gitignore.io" >&2
return 1
end
# Backup existing completions
if test -e $compl_file
mv -f $compl_file {$compl_file}.bak
else if not test -d $compl_dir
mkdir -p $compl_dir
end
# Output new completions
echo complete -c gi -a \"update-completions $gi_list\" >$compl_file
end
function gi -d "gitignore.io cli for fish"
if test $argv[1] = 'update-completions'
_update_gi_completions
return $status
end
set -l params (echo $argv|tr ' ' ',')
curl -s https://www.gitignore.io/api/$params
end
# git-flow
Completion support for git-flow.Fork from [bobthecow/git-flow-completion](https://github.com/bobthecow/git-flow-completion/blob/master/git.fish)
The contained completion routines provide support for completing:
- git-flow init and version
- feature, hotfix and release branches
- remote feature, hotfix and release branch names
# The Fine Print
Copyright (c) 2011 [Justin Hileman](http://justinhileman.com)
Distributed under the [MIT License](http://creativecommons.org/licenses/MIT/)
#!fish
#
# git-flow-completion
# ===================
#
# Fish completion support for [git-flow](http://github.com/nvie/gitflow)
#
# The contained completion routines provide support for completing:
#
# * git-flow init and version
# * feature, hotfix and release branches
# * remote feature, hotfix and release branch names
#
#
#
# The Fine Print
# --------------
#
# Copyright (c) 2012 [Justin Hileman](http://justinhileman.com)
#
# Distributed under the [MIT License](http://creativecommons.org/licenses/MIT/)
for prefix in /usr /usr/local
if test -f $prefix/share/fish/completions/git.fish
. $prefix/share/fish/completions/git.fish
break
end
end
if not functions -q __fish_git_branches
echo \nError: git completion not found >&2
exit
end
## Support functions
function __fish_git_flow_using_command
set cmd (commandline -opc)
set subcommands 'flow' $argv
if [ (count $cmd) = (math (count $subcommands) + 1) ]
for i in (seq (count $subcommands))
if not test $subcommands[$i] = $cmd[(math $i + 1)]
return 1
end
end
return 0
end
return 1
end
function __fish_git_flow_prefix
git config "gitflow.prefix.$argv[1]" 2> /dev/null; or echo "$argv[1]/"
end
function __fish_git_flow_branches
set prefix (__fish_git_flow_prefix $argv[1])
__fish_git_branches | grep "^$prefix" | sed "s,^$prefix,," | sort
end
function __fish_git_flow_remote_branches
set prefix (__fish_git_flow_prefix $argv[1])
set origin (git config gitflow.origin 2> /dev/null; or echo "origin")
git branch -r 2> /dev/null | sed "s/^ *//g" | grep "^$origin/$prefix" | sed "s,^$origin/$prefix,," | sort
end
function __fish_git_flow_untracked_branches
set branches (__fish_git_flow_branches $argv[1])
for branch in (__fish_git_flow_remote_branches $argv[1])
if not contains $branch $branches
echo $branch
end
end
end
function __fish_git_flow_unpublished_branches
set branches (__fish_git_flow_remote_branches $argv[1])
for branch in (__fish_git_flow_branches $argv[1])
if not contains $branch $branches
echo $branch
end
end
end
## git-flow
complete -f -c git -n '__fish_git_needs_command' -a flow -d 'Manage a git-flow enabled repository'
complete -f -c git -n '__fish_git_flow_using_command' -a version -d 'Show version information'
## git-flow init
complete -f -c git -n '__fish_git_flow_using_command' -a init -d 'Initialize a new git repo with support for the branching model'
complete -f -c git -n '__fish_git_flow_using_command init' -s f -d 'Force reinitialization'
complete -f -c git -n '__fish_git_flow_using_command init' -s d -d 'Use default branch names'
## git-flow feature
complete -f -c git -n '__fish_git_flow_using_command' -a feature -d 'Manage feature branches'
complete -f -c git -n '__fish_git_flow_using_command feature' -a list -d 'List feature branches'
complete -f -c git -n '__fish_git_flow_using_command feature' -s v -d 'Verbose output'
complete -f -c git -n '__fish_git_flow_using_command feature' -a start -d 'Start a new feature branch'
complete -f -c git -n '__fish_git_flow_using_command feature start' -s F -d 'Fetch from origin first'
complete -f -c git -n '__fish_git_flow_using_command feature' -a finish -d 'Finish a feature branch'
complete -f -c git -n '__fish_git_flow_using_command feature finish' -s F -d 'Fetch from origin first'
complete -f -c git -n '__fish_git_flow_using_command feature finish' -s r -d 'Rebase instead of merging'
complete -f -c git -n '__fish_git_flow_using_command feature finish' -a '(__fish_git_flow_branches feature)' -d 'Feature branch'
complete -f -c git -n '__fish_git_flow_using_command feature' -a publish -d 'Publish a feature branch to remote'
complete -f -c git -n '__fish_git_flow_using_command feature publish' -a '(__fish_git_flow_unpublished_branches feature)' -d 'Feature branch'
complete -f -c git -n '__fish_git_flow_using_command feature' -a track -d 'Checkout remote feature branch'
complete -f -c git -n '__fish_git_flow_using_command feature track' -a '(__fish_git_flow_untracked_branches feature)' -d 'Feature branch'
complete -f -c git -n '__fish_git_flow_using_command feature' -a diff -d 'Show all changes'
complete -f -c git -n '__fish_git_flow_using_command feature' -a rebase -d 'Rebase against integration branch'
complete -f -c git -n '__fish_git_flow_using_command feature rebase' -s i -d 'Do an interactive rebase'
complete -f -c git -n '__fish_git_flow_using_command feature' -a checkout -d 'Checkout local feature branch'
complete -f -c git -n '__fish_git_flow_using_command feature checkout' -a '(__fish_git_flow_branches feature)' -d 'Feature branch'
complete -f -c git -n '__fish_git_flow_using_command feature' -a pull -d 'Pull changes from remote'
complete -f -c git -n '__fish_git_flow_using_command feature pull' -a '(__fish_git_remotes)' -d 'Remote'
## git-flow release
complete -f -c git -n '__fish_git_flow_using_command' -a release -d 'Manage release branches'
complete -f -c git -n '__fish_git_flow_using_command release' -a list -d 'List release branches'
complete -f -c git -n '__fish_git_flow_using_command release' -s v -d 'Verbose output'
complete -f -c git -n '__fish_git_flow_using_command release' -a start -d 'Start a new release branch'
complete -f -c git -n '__fish_git_flow_using_command release start' -s F -d 'Fetch from origin first'
complete -f -c git -n '__fish_git_flow_using_command release' -a finish -d 'Finish a release branch'
complete -f -c git -n '__fish_git_flow_using_command release finish' -s F -d 'Fetch from origin first'
complete -f -c git -n '__fish_git_flow_using_command release finish' -s s -d 'Sign the release tag cryptographically'
complete -f -c git -n '__fish_git_flow_using_command release finish' -s u -d 'Use the given GPG-key for the digital signature (implies -s)'
complete -f -c git -n '__fish_git_flow_using_command release finish' -s m -d 'Use the given tag message'
complete -f -c git -n '__fish_git_flow_using_command release finish' -s p -d 'Push to $ORIGIN after performing finish'
complete -f -c git -n '__fish_git_flow_using_command release finish' -a '(__fish_git_flow_branches release)' -d 'Release branch'
complete -f -c git -n '__fish_git_flow_using_command release' -a publish -d 'Publish a release branch to remote'
complete -f -c git -n '__fish_git_flow_using_command release publish' -a '(__fish_git_flow_unpublished_branches release)' -d 'Release branch'
complete -f -c git -n '__fish_git_flow_using_command release' -a track -d 'Checkout remote release branch'
complete -f -c git -n '__fish_git_flow_using_command release track' -a '(__fish_git_flow_untracked_branches release)' -d 'Release branch'
## git-flow hotfix
complete -f -c git -n '__fish_git_flow_using_command' -a hotfix -d 'Manage hotfix branches'
complete -f -c git -n '__fish_git_flow_using_command hotfix' -a list -d 'List hotfix branches'
complete -f -c git -n '__fish_git_flow_using_command hotfix' -s v -d 'Verbose output'
complete -f -c git -n '__fish_git_flow_using_command hotfix' -a start -d 'Start a new hotfix branch'
complete -f -c git -n '__fish_git_flow_using_command hotfix start' -s F -d 'Fetch from origin first'
complete -f -c git -n '__fish_git_flow_using_command hotfix' -a finish -d 'Finish a hotfix branch'
complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -s F -d 'Fetch from origin first'
complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -s s -d 'Sign the hotfix tag cryptographically'
complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -s u -d 'Use the given GPG-key for the digital signature (implies -s)'
complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -s m -d 'Use the given tag message'
complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -s p -d 'Push to $ORIGIN after performing finish'
complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -a '(__fish_git_flow_branches hotfix)' -d 'Hotfix branch'
## git-flow support
complete -f -c git -n '__fish_git_flow_using_command' -a support -d 'Manage support branches'
complete -f -c git -n '__fish_git_flow_using_command support' -a list -d 'List support branches'
complete -f -c git -n '__fish_git_flow_using_command support' -s v -d 'Verbose output'
complete -f -c git -n '__fish_git_flow_using_command support' -a start -d 'Start a new support branch'
complete -f -c git -n '__fish_git_flow_using_command support start' -s F -d 'Fetch from origin first'
function gvm
bash -c '. ~/.gvm/bin/gvm-init.sh; gvm "$@"' gvm $argv
end
for gvm_path in (find $HOME/.gvm/*/current/bin -maxdepth 0)
_prepend_path $gvm_path
set -l module_info (echo $gvm_path | perl -ne 'm|(.*/.gvm/(\w+)/current)/bin| && print "$1 $2"')
set -l module_dir (echo $module_info | awk -F' ' '{print $1}')
set -l module_name (echo $module_info | awk -F' ' '{print $2}')
set -l module_home (echo $module_name | tr '[:lower:]' '[:upper:]')_HOME
set -gx "$module_home" $module_dir
end
# ONLY checked on OSX! Please add for other OS's...
if test -z $JAVA_HOME
if test -f "/usr/libexec/java_home"
set -gx JAVA_HOME (/usr/libexec/java_home)
end
if test -z $JAVA_HOME
set -l java_homes "/Library/Java/Home" "/System/Library/Frameworks/JavaVM.framework/Home"
for file in $java_homes
if test -d $file
set -gx JAVA_HOME $file
break
end
end
end
end
if test -z $JAVA_HOME
echo "GVM: JAVA_HOME not set please set JAVA_HOME."
end
jump
====
A port of [Jeroen Janssens' "jump" utility] [1] to the fish shell (and [Oh My Fish!] [2]).
[1]: http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
[2]: https://github.com/bpinto/oh-my-fish
function jump
if test (count $argv) -ne 1
echo "Usage: jump <MARK_NAME>"
else
if test -d $MARKPATH/$argv[1] -a -L $MARKPATH/$argv[1]
cd $MARKPATH/$argv[1]
else
echo "No such mark: $argv[1]"
end
end
end
set -gx MARKPATH $HOME/.marks
command mkdir -p $MARKPATH
complete -c jump -f -a '(ls ~/.marks)'
complete -c unmark -f -a '(ls ~/.marks)'
function mark
if test (count $argv) -eq 0 -o (count $argv) -gt 2
echo "Usage: mark <MARK_NAME> [DIRECTORY]"
else if test -e $MARKPATH/$argv[1]
if test -d $MARKPATH/$argv[1] -a -L $MARKPATH/$argv[1]
echo "A mark named $argv[1] already exists."
else
echo "$MARKPATH/$argv[1] already exists."
end
else if test (count $argv) -eq 1
command ln -s (pwd) $MARKPATH/$argv[1]
else if test (count $argv) -eq 2
if test -d $argv[2]
set -l current_dir (pwd)
cd $argv[2]
command ln -s (pwd) $MARKPATH/$argv[1]
cd $current_dir
else
echo "$argv[2] is not a valid directory."
end
end
end
function marks
if test (count $argv) -gt 0
echo "Usage: marks"
else
set -l file_list (command ls $MARKPATH)
if test (count $file_list) -eq 0
echo "No marks currently defined."
else
set -l mark_list
for file in $file_list
if test -d $MARKPATH/$file -a -L $MARKPATH/$file
set mark_list $mark_list $file
end
end
if test (count $mark_list) -eq 0
echo "No marks currently defined."
else
set -l current_dir (pwd)
set -l output ""
for mark_name in $mark_list
cd $MARKPATH/$mark_name
set -l real_path (pwd)
set output "$output$mark_name -> $real_path"\n
end
echo $output | column -t
cd $current_dir
end
end
end
end
function unmark
if test (count $argv) -eq 0
echo "Usage: unmark <MARK_NAME>..."
else
for mark_name in $argv
if test -d $MARKPATH/$mark_name -a -L $MARKPATH/$mark_name
command rm -i $MARKPATH/$mark_name
else
echo "No such mark: $mark_name"
end
end
end
end
# Load custom settings for current hostname
set -l HOST (hostname | sed -E 's/(-[0-9]+)?(\.(local|home))?$//')
set -l HOST_SPECIFIC_FILE $fish_custom/hosts/$HOST.fish
if test -f $HOST_SPECIFIC_FILE
. $HOST_SPECIFIC_FILE
else
echo Creating host specific file: $HOST_SPECIFIC_FILE
mkdir -p (dirname $HOST_SPECIFIC_FILE)
touch $HOST_SPECIFIC_FILE
end
# Load custom settings for current user
set -l USER_SPECIFIC_FILE $fish_custom/users/(whoami).fish
if test -f $USER_SPECIFIC_FILE
. $USER_SPECIFIC_FILE
else
echo Creating user specific file: $USER_SPECIFIC_FILE
mkdir -p (dirname $USER_SPECIFIC_FILE)
touch $USER_SPECIFIC_FILE
end
# Load custom settings for current OS
set -l PLATFORM_SPECIFIC_FILE $fish_custom/platforms/(uname -s).fish
if test -f $PLATFORM_SPECIFIC_FILE
. $PLATFORM_SPECIFIC_FILE
else
echo Creating platform specific file: $PLATFORM_SPECIFIC_FILE
mkdir -p (dirname $PLATFORM_SPECIFIC_FILE)
touch $PLATFORM_SPECIFIC_FILE
end
# Opens http://localhost:3000 (and other ports) in the default browser
#
# Usage:
#
# open a commonly used port with just the port number
# $ 3000
#
# open an arbitrary port using the `lh` command
# $ lh 3001
## Functions
function _open-installed
which open >/dev/null ^&1
end
## Main program
function lh
if _open-installed
if [ (count $argv) -lt 1 ]
echo "You need to specify a port to open"
return 1
end
command open http://localhost:$argv
else
echo 'Requires open (MacOS only) to be installed'
end
end
set -l common_localhost_ports 3000 4000 5000 6000 7000 8000 8001 9000 8080
for port in $common_localhost_ports
eval "function $port; lh $port; end"
end
function mc --description "Visual shell for Unix-like systems."
set -lx SHELL sh
if which bash > /dev/null
set SHELL (which bash)
end
command mc $argv
end
# Print a message with msg and wait for y/n input. Return true on y\*.
# @params → msg.fish
function msg.ask
msg $argv
head -n 1 | read answer
switch $answer
case y\* Y\*
return 0
case \*
return 1
end
end
# __ _ ___ ___ _
# / ' \(_-</ _ `/
# /_/_/_/___/\_, /
# /___/ v0.1.0
# NAME
# msg - technicolor message printer
#
# SYNOPSIS
# msg [-sn] [@<fg:bg> | style]<text>[style]
#
# OPTIONS
# -s
# Do not separate arguments with spaces.
# -n
# Do not output a newline at the end of the message.
#
# STYLES
# _text_ Bold
# __text__ Underline
# ___text___ Bold and Underline
# `$variable` Apply @<styles> to $variables
# /directory/ Directories
# [url] Links
# \n Line Break
# \t Tab Space
#
# @<fg:bg> fg=bg=RGB|RRGGBB|name|random
# RGB value can be any three to six hex digit or color name.
# e.g, @0fb, @tomato, @random, @error, @ok.
#
# NOTES
# Escape style separators or options prepending a \ to the
# string if inside quotes `msg "\-s"` or a \\ backslash in
# order to escape the backslash itself when outside quotes.
#
# AUTHORS
# Jorge Bucaran <jbucaran@me.com>
#
# v. 0.1.0
#/
# Global `msg` default color and styles.
set --global msg_color_fg FFFFFF
set --global msg_color_bg normal
set --global msg_style_url 00FF00 $msg_color_bg -u
set --global msg_style_dir FFA500 $msg_color_bg -u
set --global msg_color_err FF0000
set --global msg_color_ok 00FA9A
function msg -d "Technicolor printer."
# Default " " whitespace between strings, skip with -s.
set -l ws " "
# Default \n newline after message, skip with -n.
set -l ln \n
switch (count $argv)
case 0
# Nothing to print here.
return 0
case \*
switch $argv[1]
# Options must appear joined and without spaces: -sn or -ns
case -s\* -n\*
# To use options at least a second parameter will be required.
if [ (count $argv) -gt 1 ]
# Use -s to not add spaces between words.
if msg.util.str.has "s" $argv[1]
set ws ""
end
# Use -n to not add a newline at the end of the message.
if msg.util.str.has "n" $argv[1]
set ln ""
end
# We are done with options, get rid of first item.
set argv $argv[2..-1]
else
return 0
end
end
end
# Print flow is get next style token, set style, get anything else, print
# and use the reset. set_color normal makes sure to reset both colors and
# bold / underline styles.
set -l reset (set_color normal)(set_color $msg_color_fg)
# Foreground and background color carried from previous @style token.
# These variables are set and reset via msg.util.set.color
set -l fg $msg_color_fg
set -l bg $msg_color_bg
for token in $argv
switch $token
# Parse style tokens:
# _txt_, __txt__, ___txt___, @color `$var`, /dir/, [url]
case ___\*___\* __\*__\* _\*_\* \[\*\]\* \/\*\/\* `\*`\*
set -l left _ # Begin of style
set -l right _ # End of style
set -l color $fg $bg -o
switch $token
case ___\*___\* __\*__\* _\*_\*
if msg.util.str.has __ $token
set color[3] -u
set left __
if msg.util.str.has ___ $token
set color[3] -uo
set left ___
end
end
case \[\*\]\*
set color $msg_style_url
set left [ ]
set right ]
case \/\*\/\*
set color $msg_style_dir
set left \/
set right \/
case `\*`\*
set color $fg $bg
set left `
set right `
end
# Extract text between left and right separators.
echo -n (msg.util.set.color $color)(msg.util.str.get $left $token)$reset
# Extract string after separator from the right.
echo -n (printf $token | sed "s/^.*\\$right\(.*\)/\1/")$ws
# Parse @fg:bg style tokens.
case @\*
set fg (printf $token | cut -c 2-) # @fg[:bg] → fg[:bg]
set bg (printf $fg | cut -d: -f 2) # fg:bg → fg|bg
set fg (printf $fg | cut -d: -f 1) # fg:bg → fg
# Do not let bg=fg have the same color unless the user wants to.
if [ $bg = $fg ]
if not msg.util.str.has : $token
set bg $msg_color_bg
end
end
# Make color string into valid RRGGBB hex format code.
set fg (msg.util.get.color $fg)
set bg (msg.util.get.color $bg)
# Everything else, print tokens, whitespace, etc.
case \*
set -l blank $ws
switch $token
# Do not print whitespace after the following characters.
case $argv[-1] \n\* \t\* \r
set blank ""
end
switch $token
# Escape -s -n options and style separators \\[text] \\/text/
case \\\[\* \\\/\* \\\_\* \\\-s \\\-n
set token (printf $token | sed "s/^\\\//")
end
echo -en (msg.util.set.color)$token$reset$blank
end
end
echo -en $ln
end
# Translate color names to valid RRGGBB hexadecimal value.
# @params <color|random>
function msg.util.get.color
[ (count $argv) -lt 1 ]
and printf $msg_color_fg
switch $argv[1]
case success ok
printf "%s\n" $msg_color_ok
case error
printf "%s\n" $msg_color_err
case random
msg.util.random.color
case light
# Higher values produce lighter colors.
msg.util.random.color 100
case dark
# Lower values produce darker colors.
msg.util.random.color 0 75
case maroon
printf 800000
case d\*red
printf 8B0000
case brown
printf A52A2A
case firebrick
printf B22222
case crimson
printf DC143C
case red
printf FF0000
case tomato
printf FF6347
case coral
printf FF7F50
case indianred
printf CD5C5C
case l\*coral
printf F08080
case d\*salmon
printf E9967A
case salmon
printf FA8072
case l\*salmon
printf FFA07A
case orangered
printf FF4500
case d\*orange
printf FF8C00
case orange
printf FFA500
case gold
printf FFD700
case d\*goldenrod
printf B8860B
case goldenrod
printf DAA520
case palegoldenrod
printf EEE8AA
case d\*khaki
printf BDB76B
case khaki
printf F0E68C
case olive
printf 808000
case yellow
printf FFFF00
case yellowgreen
printf 9ACD32
case d\*olivegreen
printf 556B2F
case olivedrab
printf 6B8E23
case lawngreen
printf 7CFC00
case chartreuse
printf 7FFF00
case greenyellow
printf ADFF2F
case d\*green
printf 006400
case green
printf 008000
case forestgreen
printf 228B22
case lime
printf 00FF00
case limegreen
printf 32CD32
case l\*green
printf 90EE90
case palegreen
printf 98FB98
case d\*seagreen
printf 8FBC8F
case mediumspringgreen
printf 00FA9A
case springgreen
printf 00FF7F
case sea green
printf 2E8B57
case mediumaquamarine
printf 66CDAA
case mediumseagreen
printf 3CB371
case l\*seagreen
printf 20B2AA
case d\*slategray
printf 2F4F4F
case teal
printf 008080
case d\*cyan
printf 008B8B
case aqua
printf 00FFFF
case cyan
printf 00FFFF
case l\*cyan
printf E0FFFF
case d\*turquoise
printf 00CED1
case turquoise
printf 40E0D0
case mediumturquoise
printf 48D1CC
case paleturquoise
printf AFEEEE
case aquamarine
printf 7FFFD4
case powderblue
printf B0E0E6
case cadetblue
printf 5F9EA0
case steelblue
printf 4682B4
case cornflowerblue
printf 6495ED
case deepskyblue
printf 00BFFF
case dodgerblue
printf 1E90FF
case l\*blue
printf ADD8E6
case skyblue
printf 87CEEB
case l\*skyblue
printf 87CEFA
case midnightblue
printf 191970
case navy
printf 000080
case d\*blue
printf 00008B
case mediumblue
printf 0000CD
case blue
printf 0000FF
case royalblue
printf 4169E1
case blueviolet
printf 8A2BE2
case indigo
printf 4B0082
case d\*slateblue
printf 483D8B
case slateblue
printf 6A5ACD
case mediumslateblue
printf 7B68EE
case mediumpurple
printf 9370DB
case d\*magenta
printf 8B008B
case d\*violet
printf 9400D3
case d\*orchid
printf 9932CC
case mediumorchid
printf BA55D3
case purple
printf 800080
case thistle
printf D8BFD8
case plum
printf DDA0DD
case violet
printf EE82EE
case magenta fuchsia
printf FF00FF
case orchid
printf DA70D6
case mediumvioletred
printf C71585
case palevioletred
printf DB7093
case deeppink
printf FF1493
case hotpink
printf FF69B4
case l\*pink
printf FFB6C1
case pink
printf FFC0CB
case antiquewhite
printf FAEBD7
case beige
printf F5F5DC
case bisque
printf FFE4C4
case blanchedalmond
printf FFEBCD
case wheat
printf F5DEB3
case cornsilk
printf FFF8DC
case lemonchiffon
printf FFFACD
case l\*goldenrodyellow
printf FAFAD2
case l\*yellow
printf FFFFE0
case saddlebrown
printf 8B4513
case sienna
printf A0522D
case choco chocolate
printf D2691E
case peru
printf CD853F
case sandybrown
printf F4A460
case burlywood
printf DEB887
case tan
printf D2B48C
case rosybrown
printf BC8F8F
case moccasin
printf FFE4B5
case navajowhite
printf FFDEAD
case peach peachpuff
printf FFDAB9
case rose mistyrose
printf FFE4E1
case lavenderblush
printf FFF0F5
case linen
printf FAF0E6
case oldlace
printf FDF5E6
case papaya papayawhip
printf FFEFD5
case seashell
printf FFF5EE
case mintcream
printf F5FFFA
case slategray
printf 708090
case l\*slategray
printf 778899
case l\*steelblue
printf B0C4DE
case lavender
printf E6E6FA
case floralwhite
printf FFFAF0
case aliceblue
printf F0F8FF
case ghostwhite
printf F8F8FF
case honeydew
printf F0FFF0
case ivory
printf FFFFF0
case azure
printf F0FFFF
case snow
printf FFFAFA
case black
printf 000000
case dimgray dimgrey
printf 696969
case gray grey
printf 808080
case d\*gray d\*grey
printf A9A9A9
case silver
printf C0C0C0
case l\*gray l\*grey
printf D3D3D3
case gainsboro
printf DCDCDC
case whitesmoke
printf F5F5F5
case white
printf FFFFFF
case "*"
printf $argv[1]
end
end
# Print a random RRGGBB hexadecimal color from three min~max random beams
# where min = 0 and max = 255. Higher values produce lighter colors.
# @params [<min>][<max>]
function msg.util.random.color
set -l min 0
if [ (count $argv) -gt 0 ]
set min $argv[1]
end
set -l max 255
if [ (count $argv) -gt 1 ]
set max $argv[2]
end
set beam "math (random)%\($max-$min+1\)+$min"
printf "%02x%02x%02x" (eval $beam) (eval $beam) (eval $beam)
end
# Set style, fg/bg colors and reset. Modifies its parent scope of `msg`.
# @params [<fg>] [<bg>] [<style>]
function --no-scope-shadowing msg.util.set.color
if [ (count $argv) -gt 0 ]
set fg $argv[1]
end
if [ (count $argv) -gt 1 ]
set bg $argv[2]
end
set_color -b $bg
set_color $fg
if [ (count $argv) -gt 2 ]
set_color $argv[3]
end
set bg $msg_color_bg
set fg $msg_color_fg
end
# Extract string between left and right separators of variable length.
# @params <left-sep> [<right-sep>] <string>
function msg.util.str.get
set -l left $argv[1]
set -l right $argv[1]
set -l string $argv[2]
if [ (count $argv) -gt 2 ]
set right $argv[2]
set string $argv[3]
end
set -l len (printf $left | awk '{print length}')
# Match between outermost left / right separators.
printf $string | sed "s/[^\\$left]*\(\\$left.*\\$right\)*/\1/g" | \
sed "s/^.\{$len\}\(.*\).\{$len\}\$/\1/"
end
# True if substring exists in string.
# @params <substring> <string>
function msg.util.str.has
printf $argv[2] | grep -q $argv[1]
end
if test -n "$NDENV_ROOT"
_prepend_path $NDENV_ROOT/bin
_prepend_path $NDENV_ROOT/shims
else
_prepend_path $HOME/.ndenv/bin
_prepend_path $HOME/.ndenv/shims
end
### Main program
_prepend_path /usr/local/share/npm/bin
set PATH ./node_modules/.bin $PATH
if test -n "$NODENV_ROOT"
_prepend_path $NODENV_ROOT/bin
else
_prepend_path $HOME/.nodenv/bin
end
status --is-interactive; and source (nodenv init - | psub)
osx
---
**Maintainer:** [cykeb](https://github.com/CYKEB)
Inspired by the oh-my-zsh plugin by [sorin-ionescu](https://github.com/sorin-ionescu)
https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/osx/osx.plugin.zsh
- `tab` - Open the current directory in a new tab
- `pfd` - Return the path of the frontmost Finder window
- `pfs` - Return the current Finder selection
- `cdf` - cd to the current Finder directory
- `pushdf` - pushd to the current Finder directory
- `ql` - Quick Look a specified file
- `manp` - Open a specified man page in Preview
- `trash` - Move a specified file to the Trash
- `itunes` - Play, pause etc. iTunes
# cd to the current Finder directory
function cdf -d "cd to the current Finder directory"
cd (pfd)
end
\ No newline at end of file
# Play, pause etc. iTunes
function itunes -d "Play, pause etc. iTunes. Use -h or --help for a more detailed description."
if [ (count $argv) -gt 0 ]
set -l opt $argv[1]
switch $opt
case launch play pause stop rewind resume quit
case mute
set opt "set mute to true"
case unmute
set opt "set mute to false"
case next previous
set opt "$opt track"
case vol volume
set opt "set sound volume to $argv[2]"
case "" -h --help
echo "Usage: itunes <option>"
echo "option:"
echo \t"launch|play|pause|stop|rewind|resume|quit"
echo \t"mute|unmute\tcontrol volume set"
echo \t"next|previous\tplay next or previous track"
echo \t"vol"\t"Set the volume, takes an argument from 0 to 100"
echo \t"help"\t"show this message and exit"
return 0
case '*'
echo "Unknown option $opt. Use -h or --help for a more detailed description."
return 1
end
osascript -e "tell application \"iTunes\" to $opt"
else
echo "Arguments expected. Use -h or --help for a more detailed description."
end
end
\ No newline at end of file
# Open a specified man page in Preview
function manp -d "Open a specified man page in Preview"
man -t $argv | open -f -a Preview
end
\ No newline at end of file
# Return the path of the frontmost Finder window
function pfd -d "Return the path of the frontmost Finder window"
osascript 2>/dev/null -e '
tell application "Finder"
return POSIX path of (target of window 1 as alias)
end tell'
end
\ No newline at end of file
# Return the path of the frontmost Finder window
function pfs -d "Return the path of the frontmost Finder window"
osascript 2>/dev/null -e '
set output to ""
tell application "Finder" to set the_selection to selection
set item_count to count the_selection
repeat with item_index from 1 to count the_selection
if item_index is less than item_count then set the_delimiter to "\n"
if item_index is item_count then set the_delimiter to ""
set output to output & ((item item_index of the_selection as alias)\'s POSIX path) & the_delimiter
end repeat'
end
\ No newline at end of file
# pushd to the current Finder directory
function pushdf -d "pushd to the current Finder directory"
pushd (pfd)
end
\ No newline at end of file
# Quick Look a specified file
function ql -d "Quick Look a specified file"
if [ (count $argv) -gt 0 ]
qlmanage >/dev/null ^/dev/null -p Applications/ &
else
echo "No file or folder as argument given"
end
end
\ No newline at end of file
# Open the current directory in a new tab
function tab -d "Open the current directory in a new tab"
osascript 2>/dev/null -e '
tell application "System Events"
tell process "Terminal" to keystroke "t" using command down
end tell'
end
# Move a specified file to the Trash
function trash -d "Move a specified file to the Trash"
if [ (count $argv) -gt 0 ]
set -l trash_dir "$HOME/.Trash"
for item in $argv
if test -e $item
set -l item_name (basename $item)
if test -e "$trash_dir/$item_name"
set -l current_time (date "+%H.%M.%S")
mv -f "$item" "$trash_dir/$item_name $current_time"
else
mv -f "$item" "$trash_dir/"
end
end
end
else
echo "No file(s) given to delete"
end
end
\ No newline at end of file
# pbcopy
> OSX's pbcopy and pbpaste for Linux
pbcopy paste data from the clipboard to STDOUT.
pbpaste paste data from the clipboard.
## Usage
Copy a list of files in your home directory to the OS X clipboard:
```fish
$ ls ~ | pbcopy
```
Copy the contents of a file to the clipboard:
```fish
$ pbcopy < cookies.txt
```
Copy part of a file to the clipboard
```fish
$ grep 'ip address' serverlist.txt | pbcopy
```
Paste from your clipboard to stdout
echo `pbpaste`
```fish
$ pbpaste
```
Paste from your clipboard to a file
```fish
$ pbpaste > clipboard.txt
```
Paste from your clipboard to a file in a remote host
```fish
$ pbpaste | ssh username@host 'cat > ~/myclipboard.txt'
```
\ No newline at end of file
function pbcopy --description "Copy data from STDIN to the clipboard"
xsel --clipboard --input
end
function pbpaste --description "Paste data from the Clipboard"
xsel --clipboard --output
end
peco
----
Based directly on the percol plugin.
Please bind peco_select_history to your favorite key.
If you'd like to bind CTRL+R
```
function fish_user_key_bindings
bind \cr 'peco_select_history (commandline -b)'
end
```
function peco_select_history
if test (count $argv) = 0
set peco_flags --layout=bottom-up
else
set peco_flags --layout=bottom-up --query "$argv"
end
history|peco $peco_flags|read foo
if [ $foo ]
commandline $foo
else
commandline ''
end
end
Please bind percol_select_history in your favorite key.
If you'd like to bind CTRL+R
function fish_user_key_bindings
bind \cr percol_select_history
end
function percol_select_history
history|percol|read foo
if [ $foo ]
commandline $foo
else
commandline ''
end
end
# PHP HTTP server.
function phphttp
set -l port 8000
set -l path
set -l host 127.0.0.1
# 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]
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
# Help.
case -h\* --h --he --hel --help '-\?' h help
echo 'phphttp [--public] <port=8000> <path=.>'
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]
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
set port $argv[1]
end
if test (count $argv) -eq 3
set path -t$argv[2]
end
php -S$host:$port $path
end
if test -n "$PLENV_ROOT"
_prepend_path $PLENV_ROOT/bin
_prepend_path $PLENV_ROOT/shims
else
_prepend_path $HOME/.plenv/bin
_prepend_path $HOME/.plenv/shims
end
proxy plugin
============
The proxy plugin provides a couple helper functions to those of us who are
stuck behind HTTP/HTTPS/FTP proxies that require authentication. The variables
it exports are used by many command-line and GUI applications on Linux, as well
as [MacPorts][1] and [Homebrew][2] on OS X.
Both uppercase and lowercase versions of the proxy environment variables are
set, some applications are case sensitive. If you'd like to learn more about
the use of these variables, this [Arch Wiki Article][3] is a good place to
start.
## Usage
In all cases you will need to add 'proxy' to your fish_plugins list in
config.fish
### No authentication
If you just want to have the proxy plugin configure all the environment
variables, you may set proxy_host:
set proxy_host myproxy.example.com:8000
The proxy plugin will prepend `http://` for you. Here's the result:
~> set -x |grep proxy
ALL_PROXY http://myproxy.example.com:8000
FTP_PROXY http://myproxy.example.com:8000
HTTPS_PROXY http://myproxy.example.com:8000
HTTP_PROXY http://myproxy.example.com:8000
all_proxy http://myproxy.example.com:8000
ftp_proxy http://myproxy.example.com:8000
http_proxy http://myproxy.example.com:8000
https_proxy http://myproxy.example.com:8000
### With authentication
Set your proxy host and username:
set proxy_host myproxy.example.com:8000
set proxy_user mylogin
When you need to make use of the proxy, just run `proxy`. It will prompt you
for a password and setup your environment.
If you didn't setup a proxy_user variable, you will be prompted for a username.
If you wish to clear your proxy variables, run `noproxy`.
[1]: http://www.macports.org/
[2]: http://brew.sh/
[3]: https://wiki.archlinux.org/index.php/proxy_settings
function _proxy_set -a proxy \
-d "Set all proxy vars to specified value"
set -l envars http_proxy HTTP_PROXY \
https_proxy HTTPS_PROXY \
ftp_proxy FTP_PROXY \
all_proxy ALL_PROXY
for envar in $envars
if test $proxy = '-e'
set -e $envar
else
set -gx $envar $proxy
end
end
end
function noproxy -d "Clear all proxy environment variables"
_proxy_set -e
end
function proxy -d "Setup proxy environment variables"
if not set -q proxy_host
echo "Error: You must set proxy_host to your proxy hostname:port in config.fish"
echo "You may also set proxy_user to your username"
return
end
# Get user & password
set -l user $proxy_user
if not set -q proxy_user
read -p "echo -n 'Proxy User: '" user
end
# Hacky way to read password in fish
echo -n 'Proxy Password: '
stty -echo
head -n 1 | read -l pass
stty echo
echo
# URL encode password
set -l chars (echo $pass | sed -E -e 's/./\n\\0/g;/^$/d;s/\n//')
printf '%%%02x' "'"$chars"'" | read -l encpass
_proxy_set "http://$user:$encpass@$proxy_host"
end
# Initial proxy setup (no username/password)
if set -q proxy_host
_proxy_set "http://$proxy_host"
end
if test -n "$PYENV_ROOT"
_prepend_path $PYENV_ROOT/bin
_prepend_path $PYENV_ROOT/shims
else
_prepend_path $HOME/.pyenv/bin
_prepend_path $HOME/.pyenv/shims
end
# Use python2 if found, otherwise fallback to python.
function _python
if which python2
python2 $argv
else
python $argv
end
end
# beautify json string
# use : pybeautifyjson '{"foo": "lorem", "bar": "ipsum"}'
function pybeautifyjson
echo $argv | _python -mjson.tool
end
# clean current directory recursively from any .pyc and .pyo files
function pyclean
set -l path2CLEAN
if set -q $argv
set path2CLEAN .
else
set path2CLEAN $argv
end
find $path2CLEAN -name "*.py[co]" -type f -delete
end
# start in-place a simple http server, take a optional parameter for the port number
function pyhttp
if test -n "$argv"
set HTTPPORT $argv
else
set HTTPPORT 1025
end
_python -m SimpleHTTPServer $HTTPPORT;
end
# start smtp debugging server, can pass an option port parameter. Default to 1025
function pysmtp
if test -n "$argv"
set SMTPPORT $argv
else
set SMTPPORT 1025
end
echo "smtp server started on port" $SMTPPORT;
_python -m smtpd -n -c DebuggingServer localhost:$SMTPPORT;
end
function migrate
rake db:migrate db:test:clone
end
function rbenv
set command $argv[1]
set -e argv[1]
switch "$command"
case rehash shell
eval (rbenv "sh-$command" $argv)
case '*'
command rbenv "$command" $argv
end
end
# Try to find rbenv by:
# * Looking for $RBENV_BIN_ROOT/rbenv. This environment variable is specific to this plugin
# * Looking for rbenv on $PATH
# * Looking for rbenv in the user's home directory
# When necessary, prepend the bin/ directory containing rbenv to our $PATH.
if [ -e "$RBENV_BIN_ROOT/rbenv" ]
set rbenv_binary "$RBENV_BIN_ROOT/rbenv"
_prepend_path "$RBENV_BIN_ROOT"
else if [ (which command; and command command -v rbenv) ]
set rbenv_binary (command command -v rbenv)
else if [ -e "$HOME/.rbenv/bin/rbenv" ]
set rbenv_binary "$HOME/.rbenv/bin/rbenv"
_prepend_path "$HOME/.rbenv/bin"
else
echo "Could not find rbenv. Make sure it's on your system path, in your home directory or set the RBENV_BIN_ROOT environment variable pointing to the directory where you unpacked rbenv."
exit 1
end
set -l supports_fish
set -l supports_fish_version '0.4.0'
set -l user_version (eval $rbenv_binary --version | sed -E 's/^rbenv ([[:digit:]\.]{2,}).*$/\1/g')
if [ $user_version = $supports_fish_version ]
set -l supports_fish_commits '56'
set -l user_commits (eval $rbenv_binary --version | sed -E 's/^.+-([[:digit:]]{1,}).+$/\1/g')
if [ $user_commits -ge $supports_fish_commits ]
set supports_fish true
end
else
set -l higher_version (echo -e "$supports_fish_version\n$user_version" | \
sort --field-separator . \
--key 1,1 --numeric-sort --reverse \
--key 2,2 --numeric-sort --reverse \
--key 3,3 --numeric-sort --reverse | \
head -n 1)
if [ $user_version = $higher_version ]
set supports_fish true
end
end
if [ $supports_fish ]
status --is-interactive; and source (eval $rbenv_binary init - | psub)
else
if [ "$RBENV_ROOT" ]
_prepend_path "$RBENV_ROOT/shims"
else
_prepend_path "$HOME/.rbenv/shims"
end
end
function replace --description 'Find and replace by a given list of files.'
set find_this $argv[1]
set replace_with $argv[2]
ag -l $find_this $argv[3..-1] | xargs sed -i '' "s/$find_this/$replace_with/g"
end
function rvm -d 'Ruby enVironment Manager'
# run RVM and capture the resulting environment
set -l env_file (mktemp -t rvm.fish.XXXXXXXXXX)
bash -c '[ -e ~/.rvm/scripts/rvm ] && source ~/.rvm/scripts/rvm || source /usr/local/rvm/scripts/rvm; rvm "$@"; status=$?; env > "$0"; exit $status' $env_file $argv
# grep the rvm_* *PATH RUBY_* GEM_* variables from the captured environment
# exclude lines with _clr and _debug
# apply rvm_* *PATH RUBY_* GEM_* variables from the captured environment
and eval (grep '^rvm\|^[^=]*PATH\|^RUBY_\|^GEM_' $env_file |grep -v _clr |grep -v _debug| sed '/^[^=]*PATH/y/:/ /; s/^/set -xg /; s/=/ /; s/$/ ;/; s/(//; s/)//')
# clean up
rm -f $env_file
end
rvm current 1>/dev/null 2>&1
function __check_rvm --on-variable PWD --description 'Setup rvm on directory change'
status --is-command-substitution; and return
if test "$rvm_project_rvmrc" != 0
set -l cwd $PWD
while true
if contains $cwd "" $HOME "/"
if test "$rvm_project_rvmrc_default" = 1
rvm default 1>/dev/null 2>&1
end
break
else
if begin ; test -s ".rvmrc" ; or test -s ".ruby-version" ; or test -s ".ruby-gemset" ; or test -s ".versions.conf" ; end
rvm reload 1> /dev/null 2>&1
rvm rvmrc load 1>/dev/null 2>&1
break
else
set cwd (dirname "$cwd")
end
end
end
set -e cwd
end
end
## ssh conservative $TERM value helper
Due to inconsistency of 256 color terminal support across
terminal applications, it may be desirable to force the
$TERM value to it's -256color variant.
For example, this is often accomplished in tmux by means
of adding the following to a tmux.conf file:
set -g default-terminal "screen-256color"
Unfortunately, remote hosts accessed via ssh may not have
the requisite terminfo files, and may not even allow the
user to supply them, as is often the case with network
equipment and other appliances accessible via ssh.
This helper strips the -256color suffix and exports a
regular 'screen' or 'xterm' $TERM value when setting up
a ssh connection.
function ssh --description 'OpenSSH SSH client (remote login program) with a conservative $TERM value'
switch $TERM
case screen-256color
set -lx TERM screen
command ssh $argv
case xterm-256color
set -lx TERM xterm
command ssh $argv
case '*'
command ssh $argv
end
end
function subl --description 'Open Sublime Text'
if test -d "/Applications/Sublime Text.app"
"/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" $argv
else if test -d "/Applications/Sublime Text 2.app"
"/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" $argv
else if test -d "$HOME/Applications/Sublime Text.app"
eval "$HOME/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl" $argv
else if test -d "$HOME/Applications/Sublime Text 2.app"
eval "$HOME/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl" $argv
else if test -x "/opt/sublime_text/sublime_text"
"/opt/sublime_text/sublime_text" $argv
else if test -x "/opt/sublime_text_3/sublime_text"
"/opt/sublime_text_3/sublime_text" $argv
else
echo "No Sublime Text installation found"
end
end
The MIT License (MIT)
Copyright (c) 2015 Jorge Bucaran
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
<a name="ta"></a><em>
<p align="center">
:ledger: <b>ta</b>
|
<b><a href="#features">Features</a></b>
|
<b><a href="#rationale">Rationale</a></b>
|
<b><a href="#install">Install</a></b>
|
<b><a href="#synopsis">Synopsis</a></b>
|
<b><a href="#issues">Issues</a></b>
|
<b><a href="#about">?</a></b>
</p>
<p align="center">
<img width=65% height=65% src ="images/ta.png">
</p>
___ta___ is a CLI-based _to-done_ task manager. The advantage over _to-do_ lists are:
1. You __don't__ change your routine or habits.
2. You __don't__ need to follow a predictable workflow.
3. You focus on completing stuff first. Log. Repeat.
4. Tasks are [inmutable](#undoing-tasks). Like time travel.
See [rationale](#rationale) for a more lengthy discussion.
## <a name="features">Features</a>
<p align="center">
<table>
<tr>
<tr>
<th>1. <a href="#adding-tasks">Adding Tasks</a></th>
<th>2. <a href="#undoing-tasks">Undoing Tasks</a></th>
<th>3. <a href="#searching-tasks">Searching Tasks</a></th>
</tr>
<tr>
<td><img src="images/add.png"></td>
<td><img src="images/undo.png"></td>
<td><img src="images/tags.png"></td>
</tr>
</tr>
<tr>
<th>4. <a href="#searching-tasks">Regex</a></th>
<th>5. <a href="#navigating-tasks">Navigating Tasks</a></th>
<th>6. <a href="#recent-tasks">Recent Task Marker</a></th>
<tr>
<td><img src="images/regex.png"></td>
<td><img src="images/list.png"></td>
<td><img src="images/recent.png"></td>
</tr>
</tr>
</table>
<p align="right">
<a href="#ta">:arrow_up:</a> <a href="#ta">Top</a></p>
</p>
<hr>
### <a name="adding-tasks">Adding Tasks</a>
* `ta "called #mom"`
* `ta "pushed ta to #gh #projects"`
### <a name="undoing-tasks">Undoing Tasks</a>
Tasks in _ta_ are, by definition, inmutable. It's like time travel. You are not allowed.
It _is_ possible, however, to undo _only_ the most recent task:
* `ta -u` or `ta --undo`
> __Note__: _ta_ is a productivity tool to help you improve your workflow, but it's not a task scheduler. If you are looking for a traditional _to-do_ manager I recommend looking at [Swatto/td](https://github.com/Swatto/td).
### <a name="searching-tasks">Searching Tasks</a>
Use `-s --search <tag>` to search for tasks tagged by `<tag>`.
* `ta -s spanish+jul`
List _#spanish_ tasks in July.
* `ta -s work+opensource`
List _#work_ __and__ _#opensource_ tasks.
* `ta --search family+friends -n5`
List _#family_ __and__ _#friends_ tasks. _5 max._
Use `--regex -s <query>` or `-rs <query>` to search by an arbitrary regular expression.
* `ta -rs "workout|cardio|gym"`
List __all__ _#workout_, _#cardio_ __or__ _#gym_ tasks
### <a name="navigating-tasks">Navigating Tasks</a>
Simply type `ta` to display all tasks. The task at the top is the most recent one.
The list dump is piped into [`less`](http://linux.die.net/man/1/less) so you can easily navigate up and down, run inline searches, etc.
[See here](http://bit.ly/17qd1KM) for a full list of options.
<p align="center">
<img width=80% height=80% src ="images/full-list.png">
</p>
You can also limit the number of tasks using the `-n --number <number>` option.
### <a name="recent-tasks">Recent Tasks</a>
If you complete any task within ten minutes of the previously added task, the `*` marker will turn red. It's up to you to interpret that as either a good or a bad sign.
<p align="right">
<a href="#ta">:arrow_up:</a> <a href="#ta">Top</a></p>
## <a name="rationale">Rationale</a>
In a todo-like system, each task is a promise scheduled to be fulfilled
in the future. In practice, promises can be hard to keep and prioritize.
GTD-like methods offer good strategies to help with this, but they often
require breaking die-to-hard habits and can be too complicated for users.
Information flux is unpredictable, and dividing how this information is
collected and processed in often overlapping stages is challenging.
A to-done approach is not incompatible with traditional todo-lists, but
it was created in a world where todo lists are not prominent.
The premise is, as information flow crosses over the singularity threshold,
data-collection and sorting becomes impossible and unwieldy. The contract
is to spend _less_ time prioritizing and concentrate in completing only _one_
task at a time. Only completed tasks can be logged into the system.
Overall happiness and motivation increase will be directly proportional
to the number of completed tasks.
<p align="right">
<a href="#ta">:arrow_up:</a> <a href="#ta">Top</a></p>
## <a name="install">Install</a>
### Fish
#### _Oh-my-fish_
Add the `ta` plugin to `$fish_plugins` via `~/.config/fish` or from your prompt:
```fish
set -g fish_plugins $fish_plugins ta
```
#### _Standalone_
Trust me and run:
```fish
curl -L http://git.io/install-ta | fish
ta "just installed #ta #right-move"
```
or if you are so inclined have a look at [`tools/install`](tools/install)
You can also specify the installation path:
```fish
curl -L http://git.io/install-ta | env INSTALL_PATH="to/your/path/" fish
ta "just installed #ta #right-move"
```
#### <a name="uninstall"></a> Uninstall
```fish
fish $ta_path/tools/uninstall
```
<p align="right">
<a href="#ta">:arrow_up:</a> <a href="#ta">Top</a></p>
## <a name="synopsis">Synopsis</a>
```
ta [<task #tag1 #tag2...">]
[-u --undo]
[-s --search <key[+key...]>]
[-r --regex]
[-n --number <number>]
[-h --help]
[--version]
```
### ta _task_
Add a completed task. Append a :hash: to keywords to apply tags.
Simply run `ta` without arguments to list all completed tasks.
### -s --search _key_[, ...]
Search tasks tagged by _key_.
Use `+` to search tasks with all the specified tags.
Use the `-r` option and concatenate keys with `|` to search for all tasks with any of the specified tags.
#### Special Tags
The following tags are never displayed in results, but available to use in search queries:
* Weekdays: `mon...sun`
* Month: `jan...dec`
* Day: `1st, 2nd, 3rd, 4th...31st`
* Time: `12am...12pm`
> __Note__: These tags are added automatically to each task depending on the current time and date.
### -r --regex
Use together with `-s` and evaluate _key_ as a regular expression.
### -n --number _N_
Truncate number of results to _N_.
### -u --undo
Delete most recent task.
> __Note__: Using this option locks the ability to undo until a new task is committed protecting users from engaging in useless housekeeping habits.
### -h --help
Show usage help.
### --version
Show version information and trivia info.
<p align="right">
<a href="#ta">:arrow_up:</a> <a href="#ta">Top</a></p>
## <a name="issues">Issues</a>
I welcome your [feedback, comments, opinions, bug reports](https://github.com/bucaran/ta/issues) and/or [PR](https://github.com/bucaran/ta/issues)s. Thanks.
## <a name="about">About</a>
If you are curious, ___ta___ or rather __た__, is a conjugation / deflection used in
Japanese to indicate the completion of an action ([perfective aspect](http://en.wikipedia.org/wiki/Perfective_aspect)), roughly corresponding
to the past tense in western languages.
<p align="right">
<a href="#ta">:arrow_up:</a> <a href="#ta">Top</a></p>
## <a name="license">License</a>
[MIT](http://opensource.org/licenses/MIT) :heart: [Jorge Bucaran](https://github.com/bucaran)
function ta.cli.clear
set -l bright_color (set_color FF1493)
set -l normal_color (set_color normal)
set -l question "[$bright_color"Y"$normal_color/n]"
if not test -e $__ta_file_data
echo "Nothing to clear."
return $__ta_error_no_tasks
end
echo -n "Delete all data? $question: "
head -n 1 | read answer
switch $answer
case Y yes
rm $__ta_file_data
echo "Done"
end
end
function ta.cli.commit -a task
# We delay the elapsed counter until the first task is committed.
set -q __ta_elapsed
or set -g __ta_elapsed (date "+%s")
set -l now (date "+%s")
set __ta_delta (math $now - $__ta_elapsed)
set __ta_elapsed $now
set -l meta (ta.util.tags.get.meta)
# Trim extra whitespace and save file.
echo -se (echo "$task" \
| tr -s '[:space:]' ' ')\t"$meta" >> $__ta_file_data
if test $status -eq 0
ta.cli.search "" | head -n2
# Unlock undo stack.
set __ta_undo_lock false
end
end
function ta.cli.help
echo "
USAGE
ta [<task #tag #tag...>]
[-u --undo]
[-s --search <key[+key...]>]
[-r --regex]
[-n --number <number>]
[-h --help]
[--clear]
[--version]
"
end
function ta.cli.search -a keys number
if not test -e $__ta_file_data
echo "There are no tasks."
return $__ta_error_no_tasks
end
set -l result
set -l flags
set -q argv[3]
and set flags $argv[3..-1]
# UI colors.
set -l tag_color "1;93"
set -l grep_color "0;103;1;90"
set -l text_color (set_color 777)
set -l query_color (set_color FF1493)
set -l normal_color (set_color normal)
if test -n "$number"
# Truncate results via tail -n$number
set number "n$number"
end
if contains -- regex $flags
set result (env GREP_COLOR="$grep_color" \
grep --color=always -E "$keys" $__ta_file_data)
else
set result (cat $__ta_file_data)
if test -n "$keys"
for key in (echo "$keys" | tr + \n)
# grep results consecutively to produce an AND operator.
# Notice we append a `#' to the $key to filter only tags.
set result (printf "%s\n" $result | grep "#$key")
end
end
end
if test -z "$result"
echo "Nothing to see here."
return $__ta_error_no_tasks
end
# Trim special flags, print results in reverse and color #tags.
if set result (printf "%s\n" $result \
| cut -d\t -f1 | tail -r"$number" \
| ta.util.color.tags $tag_color)
# Append |$ at the end of the tag regex to make sure grep prints all
# incoming lines from the tail pipe, but colors only tags. $ matches
# the end of all lines but has nothing to colorize.
set -l count (count $result)
set -l s # Plural?
test $count -gt 1; and set s "s"
# If both keys and number are empty just print tasks.
if test -z "$keys" -a -z "$number"
# set count (ta.util.tasks.count)
echo $text_color"$count task$s completed."$normal_color
if test $count -gt 0
set -l mark_color (set_color blue)
# Task marker is red if the task was completed within 10 mins.
if test $__ta_delta -gt 0 -a $__ta_delta -lt 600
set mark_color (set_color red)
end
echo -n $mark_color\* $normal_color
end
else
if test -n "$keys"
echo /$query_color"$keys"$normal_color/ | begin
# Only for tag search, colorize `+' characters for love.
if not contains -- regex $keys
sed "s/+/$normal_color+$query_color/g"
end
end
end
echo $text_color"$count result$s."$normal_color
end
printf "%s\n" $result
end
end
function ta.cli.undo
if test $__ta_undo_lock = false
if test (ta.util.tasks.count) -gt 0
# Display task for the last time.
ta.util.get.tail | grep -E --color=always ".*"
if sed -Ei.bak '$ d' $__ta_file_data
rm $__ta_file_data.bak
else
set -l code $status
cp $__ta_file_data.bak $__ta_file_data
return $code
end
set -g __ta_undo_lock true
else
echo "There are no tasks."
return $__ta_error_no_tasks
end
end
echo "The undo stack is locked until a new task is added."
end
function ta.cli.version
set -l name (ta.util.tafile.get.key name)
set -l tagline (ta.util.tafile.get.key tagline)
set -l ver (ta.util.tafile.get.key version)
echo $name - (set_color yellow)$tagline(set_color normal) $ver
echo -s (set_color 777)"
If you are curious, ta or rather た, is a particle / deflection used in
Japanese to indicate the completion of an action, roughly corresponding
to the past tense in some western languages.
"(set_color normal)\
"
Now go get some stuff done!"
end
name,ta
tagline,to-done manager
version,1.0
import plugins/fish-spec
import plugins/ta
function describe_ta -d "ta: to-done task manager"
function before_all
end
function after_all
end
function it_does_something
end
end
# spec.run $argv
# NAME
# ta - to-done manager
#
# SYNOPSIS
# ta [<task #tag #tag...>]
# [-u --undo]
# [-s --search <key[+key...]>]
# [-r --regex]
# [-n --number <number>]
# [-h --help]
# [--clear]
# [--version]
#
# USAGE
# [<task>]
# Add new completed task. Append a `#' to keywords to apply tags.
# Simply run ta without arguments to list all completed tasks.
#
# -s --search <key[,...]>
# Search tasks tagged by <key>. Use `+' to search tasks with all
# the specified tags. Use -r and `|' to search for tasks with at
# least one of the specified tags
#
# Some tags are automatically created based in the current date:
#
# Weekdays mon...sun
# Month jan...dec
# Day 1st, 2nd, 3rd, 4th...31st
# Time 12am...12pm
#
# -r --regex {-s<key>}
# Use <key> as a regular expression.
#
# -n --number <number>
# Truncate results to <number>.
#
# -u --undo
# Delete most recent task. Using this option locks the ability to undo
# until a new task is committed. This protects users from engaging in
# useless housekeeping habits.
#
# -h --help
# Show usage help.
#
# --clear
# Clear all data. Use with caution.
#
# --version
# Show version information.
#
# EXAMPLES
# Add a task.
# ta "talked to #mom #family"
#
# List all `spanish` tasks in July.
# ta -s spanish+jul
#
# List all `work` AND `opensource` tasks.
# ta -s work+opensource
#
# List all `workout` OR `cardio` OR `gym` tasks.
# ta -rs workout\|cardio\|gym
#
# List all `family` AND `friends` tasks. Show 5 most recent.
# ta --search family+friends -n5
#
# DESCRIPTION
# In a todo-like system, each task is a promise scheduled to be fullfilled
# in the future. In practice, promises can be hard to keep and prioritize.
#
# GTD-like methods offer good strategies to help with this, but they often
# require breaking die-to-hard habits and can be too complicated for users.
#
# Information flux is unpredictable, and dividing how this information is
# collected and processed in often overlapping stages is challenging.
#
# A to-done approach is not incompatible with traditional todo-lists, but
# it was created in a world where todo lists are not prominent.
#
# The premise is as information flow crosses over the singularity threshold
# data-collection and sorting becomes impossible and unwieldy. The contract
# is to spend less time prioritizing and concentrate in completing only one
# task at a time. Only completed tasks can be logged into the system.
#
# Overall happiness and motivation increase will be directly proportional
# to the number of completed tasks.
#
# AUTHORS
# Jorge Bucaran <jbucaran@me.com>
#/
function ta -d "to-done manager"
set -l flags
while set opts (getopts ":s:search: n:number: r:regex
u:undo h:help clear version" $argv)
switch $opts[1]
case s n
set flags $flags search
if test $opts[1] = n
set number $opts[2]
else
set search $opts[2]
end
case r
set flags $flags regex
case u
set flags undo
case h
set flags help
case clear
set flags clear
case version
set flags version
end
end
if test $status -gt 1
ta.cli.help
return $__ta_error_bad_input
else if contains -- undo $flags
ta.cli.undo
else if contains -- search $flags
# Pipe to less with color, left-width and verbose status bar.
ta.cli.search "$search" "$number" $flags \
| less -JM --raw-control-chars
else if contains -- version $flags
ta.cli.version
else if contains -- clear $flags
ta.cli.clear
else if test -n "$opts"
ta.cli.commit "$opts"
else if contains -- help $flags
ta.cli.help
else
ta --search ""
end
end
set -g __ta_error 1
set -g __ta_error_bad_input 2
set -g __ta_error_no_tasks 3
# Standalone installation.
if set -q ta_path
for file in $ta_path/**
switch $file
case \*.fish
set -l dir (dirname $file)
# Skip completions and spec directories.
if test (basename $dir) != "completions" -a \
(basename $dir) != "spec"
if not contains -- "$dir" $fish_function_path
set fish_function_path "$dir" $fish_function_path
end
end
end
end
# Oh-my-fish installation.
else if set -q fish_path
set -g ta_path $fish_path/plugins/ta
# Oh-my-fish lets you import modules easily. For standalone fish
# installations, fish getopts is already included in the path.
import plugins/getopts
else
# Neither $INSTALL_PATH or $fish_path exists.
echo "Please review the installation instructions and try again." ^&2
exit $__ta_error
end
set -g __ta_file_info $ta_path/config/tafile
set -g __ta_file_data $ta_path/data/tasks
# Regular expression used to extract tags from tasks.
set -g __ta_regex "#\S*"
# Seconds elapsed between last and current task to commit.
set -g __ta_delta 0
# Flag to track whether the undo stack is locked. Tasks are usually
# inmutable except for the most recent task to allow simple mistake
# correction.
set -q __ta_undo_lock
or set -g __ta_undo_lock false
function ta.util.color.tags -a color
env GREP_COLOR="$color" grep --color=always -E "$__ta_regex|\$"
end
function ta.util.get.tail
tail -rn1 $__ta_file_data \
| cut -f1
end
function ta.util.tafile.get.key -a key
grep -E "\b$key\b" $__ta_file_info | cut -d, -f2
end
function ta.util.tags.get -a task
echo "$task" | tr -s "[:space:]" \n | grep -Eo "$__ta_regex" | cut -c2-
end
function ta.util.tags.get.meta
set -l week (date +%a)
set -l day (date +%d)
switch $day
case 1 21 31
set $day "$day"st
case 2 22
set $day "$day"nd
case 3 23
set $day "$day"rd
case \*
set $day "$day"th
end
set -l month (date +%b)
set -l year (date +%Y)
set -l hour (date "+%r" | \
sed -E "s/0?([1-9][0-9]?).*(..)/\1\2/")
printf "#%s " $week $day $month $year $hour | awk '{print tolower}'
end
function ta.util.tasks.count
wc -l < $__ta_file_data | awk '{print $1}'
end
# Open new iTerm and Terminal tabs from the command line
#
# Author: Justin Hileman (http://justinhileman.com)
#
# Usage:
# tab Opens the current directory in a new tab
# tab [PATH] Open PATH in a new tab
# tab [CMD] Open a new tab and execute CMD
# tab [PATH] [CMD] ... You can prolly guess
#
# If you use iTerm and your default session profile isn't "Default Session",
# override it in your config.fish
#
# set -g tab_iterm_profile "MyProfile"
function tab -d 'Open the current directory (or any other directory) in a new tab'
set -l cmd ''
set -l cdto $PWD
if test (count $argv) -gt 0
if test -d $argv[1]
pushd . >/dev/null
cd $argv[1]
set cdto $PWD
set -e argv[1]
popd >/dev/null
end
end
if test (count $argv) -gt 0
set cmd "; $argv"
end
switch $TERM_PROGRAM
case 'iTerm.app'
set -l profile 'Default Session'
if set -q tab_iterm_profile
set profile $tab_iterm_profile
end
osascript 2>/dev/null -e "
tell application \"iTerm\"
tell current terminal
launch session \"$profile\"
tell the last session
write text \"cd \\\"$cdto\\\"$cmd\"
end tell
end tell
end tell
"
case 'Apple_Terminal'
osascript 2>/dev/null -e "
tell application \"Terminal\"
activate
tell application \"System Events\" to keystroke \"t\" using command down
repeat while contents of selected tab of window 1 starts with linefeed
delay 0.01
end repeat
do script \"cd \\\"$cdto\\\"$cmd\" in window 1
end tell
"
case '*'
echo "Unknown terminal: $TERM_PROGRAM" >&2
end
end
## _theme_ :tophat:
> Quick theme switcher.
## Description
Quick theme switcher for _Oh my fish_. _theme_ is smart to auto-complete as you type all the available _oh-my-fish_ themes.
![mov](https://cloud.githubusercontent.com/assets/8317250/6200763/8593a226-b4c9-11e4-9845-597be49d3233.gif)
## Options
#### `theme <theme name>`
Quick switch to theme.
#### `theme -l --list`
List available themes.
#### `theme -r --restore`
Restore original theme.
#### `theme -h --help`
Show usage help.
## Authors
+ [Jorge Bucaran](https://github.com/bucaran)
## Credits
+ Auto-completions thanks to [Bruno Pinto](https://github.com/bpinto).
## License
MIT
# Add completions when the theme is loaded. Thanks Bruno!
complete --command (basename -s.fish (status -f)) \
--arguments "(basename (theme.util.get.themes))" \
--description "Oh-my-fish theme"
import plugins/fish-spec
import plugins/theme
function describe_theme -d "theme: quick theme switcher"
function before_all
set -g __theme_test_last_theme $fish_theme
end
function it_changes_the_current_theme
theme bobthefish
expect $fish_theme --to-equal bobthefish
and expect $fish_function_path --to-contain-all $fish_path/themes/bobthefish
end
function it_restores_the_original_theme
theme bobthefish
theme -r
expect $fish_theme --to-equal $__theme_test_last_theme
end
function it_prints_usage_help
expect (theme -h | grep USAGE | sed -E 's/ //g') --to-equal "USAGE"
end
function it_prints_a_list_of_all_themes
set -l themes (theme -l)
for theme in $fish_custom/themes/* $fish_path/themes/*
set theme (basename "$theme")
expect (echo "$themes" | grep -o "$theme") --to-equal "$theme"
end
end
function it_highlights_the_currently_selected_theme
set -l themes (theme -l)
expect (echo "$themes" | grep -o "$fish_theme\*") --to-equal "$fish_theme*"
end
function it_can_reload_a_theme_multiple_times
theme bobthefish
theme fishface
theme bobthefish
expect $fish_theme --to-equal bobthefish
and expect $fish_function_path --to-contain-all $fish_path/themes/bobthefish
and expect $fish_function_path --to-not-contain-all $fish_path/themes/fishface
end
function it_returns_1_if_the_theme_does_not_exist
set -l improbable_theme ___(date +%s)___
set -l ignore_output (theme "$improbable_theme")
expect $status --to-equal 1
end
end
spec.run $argv
# NAME
# theme - quick theme switcher
#
# DESCRIPTION
# Quick theme switcher for Oh my fish. theme is smart to auto-complete
# as you type from the list available _oh-my-fish_ themes.
#
# SYNOPSIS
# theme <theme name>
# [-l --list]
# [-u --update]
# [-r --restore]
# [-h --help]
#
# OPTIONS
# theme <theme name>
# Quick switch to theme.
#
# theme -l --list
# List available themes.
#
# theme -u --update
# Update theme auto-completions.
#
# theme -r --restore
# Restore original theme.
#
# theme -h --help
# Show usage help.
#
# AUTHORS
# Jorge Bucaran <jbucaran@me.com>
# /
if not set -q __fish_theme_last
set -g __fish_theme_last $fish_theme
end
function theme -d "quick theme switcher"
set -l usage "
USAGE
$_ <theme name>
Quick switch to theme.
$_ -l --list
List available themes.
$_ -r --restore
Restore original theme.
$_ -h --help
Show usage help.
"
if test (count $argv) -gt 0
set -l option $argv[1]
switch $option
case -h --help help
echo $usage
case -l --list
set -l regex "[[:<:]]($fish_theme)[[:>:]]"
if test (uname) != "Darwin"
set regex "\b($fish_theme)\b"
end
set -l color green
for theme in (theme.util.get.themes)
basename $theme \
| sed -E "s/$regex/"(set_color $color)"\1*"(set_color normal)"/"
end | column
set_color normal
case -r --restore
if set -q __fish_theme_last
if test $__fish_theme_last != $fish_theme
theme.util.remove.current
set fish_theme $__fish_theme_last
. $fish_path/oh-my-fish.fish
end
end
case \*
if test -z "$option"
echo $usage
else if test -d $fish_custom/themes/$option -o \
-d $fish_path/themes/$option
theme.util.remove.current
set fish_theme $option
. $fish_path/oh-my-fish.fish
else
echo (set_color f00)"`$option` is not a theme."(set_color normal) ^&2
theme --list
return 1
end
end
else
theme --list
end
end
function theme.util.get.themes
printf "%s\n" $fish_path/themes/*
end
function theme.util.remove.current
# Find previously loaded theme index in function path.
set -l index (contains -i -- \
$fish_custom/themes/$fish_theme $fish_function_path)
if test $status -gt 0
# Not a custom theme, try a default theme.
set index (contains -i -- \
$fish_path/themes/$fish_theme $fish_function_path)
end
if test -n "$index"
# So Long, and Thanks for All the Fish.
set -e fish_function_path[$index]
end
end
# _tiny_
> git.io for the lazy
## Synopsis
```
tiny [-u --user <username>]
[-r --repo <repository>]
[-c --code <vanity code>]
[-o --open]
[-h --help]
tiny [-c --code] [-o --open] owned-repo/url
```
## Description
Tap into [git.io](http://git.io), github's URL shortener service, to easily _shorten_ any github URL. The generated URL is printed to `stdout` and copied to the clipboard. You can optionally specify the `-o` flag to open it up on your browser too.
## Options
#### `-u --user`
Username. If omitted, the git global config is queried.
#### `-r --repo`
Repository name.
#### `-c --code`
Own code to setup a personal `vanity` URL. A regular short URL is generated if the specified code is not available.
#### `-o --open`
Open the short URL in the browser.
#### `-h --help`
Display usage help.
## Default Options
It's possible to omit the `-u` option and just specify the `url` to shorten.
```fish
tiny my-awesome-repo
```
In this case, the username will be retrieved from your git configuration file. You can add your github username to git's configuration like this:
```fish
git config github.user <your username>
```
Another common use case is to simply copy paste an existing URL into the terminal:
```fish
tiny [-o --open] http://github.com/facebook/react
```
## Diagnostics
The following error codes are generated:
+ _1_ git.io failed to shorten the URL
+ _2_ invalid input or no input.
## Links
+ [git.io](http://git.io)
+ [Github's URL shortener](https://github.com/blog/985-git-io-github-url-shortener)
## License
[MIT](http://opensource.org/licenses/MIT) © [Jorge Bucaran](https://bucaran.me)
import plugins/fish-spec
import plugins/tiny
function describe_tiny -d "tiny (git.io ULR shortener)"
function it_generates_a_short_url
expect (tiny -u facebook -r react | cut -d/ -f3) --to-equal git.io
end
function it_prints_usage_if_there_is_no_input
expect (tiny | grep USAGE) --to-equal " USAGE"
end
function it_returns_1_if_gitio_fails
tiny https://notgithub.com/bad/url
expect $status --to-equal 1
end
function it_returns_2_if_there_is_an_invalid_option
set -l ignore_output (tiny --wrong-option)
expect $status --to-equal 2
end
function it_returns_2_if_there_is_no_user_or_repo_specified
set -l ignore_output (tiny)
expect $status --to-equal 2
end
function it_prints_usage_if_there_is_an_invalid_option
expect (tiny -x | grep USAGE) --to-equal " USAGE"
end
function it_prints_help_if_no_global_user_is_configured
set github_user_copy (git config --local github.user)
git config --local github.user ""
expect (tiny --repo whos-repo | head -c7) --to-equal "Specify"
expect $status --to-equal 2
git config --local github.user "$github_user_copy"
end
end
spec.run $argv
# NAME
# tiny - tap into github's git.io URL shortener
#
# SYNOPSIS
# tiny [-u --user <username>]
# [-r --repo <repository>]
# [-c --code <vanity code>]
# [-o --open]
# [-h --help]
#
# tiny [-c --code] [-o --open] owned-repo/url
#
# DESCRIPTION
# Tap into git.io, github's URL shortener service, to easily shorten any
# github URL. The generated URL is printed to `stdout` and copied to the
# clipboard. You can optionally specify the `-o` flag to open it up on
# your browser too.
#
# OPTIONS
# -u --user Username. If omitted, query the git global config.
# -r --repo Repository.
# -c --code Own code to setup a personal `vanity` URL. A regular short
# URL is generated if the specified code is not available.
# -o --open Open the short URL in the browser.
# -h --help Display usage help.
#
# DEFAULT OPTIONS
# It's possible to omit the `-u` option and just specify the `url` to
# shorten.
#
# tiny my-awesome-repo
#
# In this case, the username will be retrieved from your git config.
# You can add your github username to git's config like this:
#
# git config github.user <your username>
#
# Another common use case is to simply copy paste an existing URL into
# the terminal:
#
# tiny [-o --open] http://github.com/facebook/react
#
# DIAGNOSTICS
# The following error codes are generated:
# 1 git.io failed to shorten the URL
# 2 invalid input or no input
#
# LINKS
# github.com/blog/985-git-io-github-url-shortener
# /
import plugins/getopts
function github.io -a url code
if test -n "$code"
set code -F code=$code
end
# Extract URL from the response an remove an annoying \r at the end.
curl -is http://git.io/ -F url="$url" $code \
| grep "Location: http" | cut -c11- \
| awk '{print substr($0, 1, length($0) - 1)}'
end
function tiny -d "get a git.io short URL"
set -l __github_url "https://github.com"
set -l __github_user (git config github.user)
set -l __TINY_ERR_BAD_URL 1
set -l __TINY_ERR_BAD_INPUT 2
while set opts (getopts ":o:open u:user: r:repo: c:code: h:help" $argv)
switch $opts[1]
case o
set open true
case u
set user $opts[2]
case r
set repo $opts[2]
case c
set code $opts[2]
case h
tiny.help
end
end
test $status -gt 1
and tiny.help
and return $__TINY_ERR_BAD_INPUT
if echo "$opts" | grep --silent "http"
set url "$opts"
else if test -n "$opts"
# To allow the covenience of `tiny [OPTS] repo` → `tiny [OPTS] -r repo`
set repo "$opts"
end
if not set -q url
if not set -q user
if not set -q repo
tiny.help
return $__TINY_ERR_BAD_INPUT
end
set user $__github_user
if test -z "$user"
echo "Specify a username via the -u option or save it to your git config."
echo -sn (set_color ccc) "e.g., git config --global github.user"
echo (set_color yellow) "username"
return $__TINY_ERR_BAD_INPUT
end
end
set url "$__github_url/$user/$repo" "$code"
end
set url (github.io $url)
if test -n "$url"
if test (uname) != "Darwin"
import plugins/pbcopy
end
# Print to stdout, copy to stderr pipe it into pbcopy.
echo "$url" | tee /dev/stderr ^| pbcopy ^/dev/null
set -q open
and open "$url"
or true
else
return $__TINY_ERR_BAD_URL
end
end
function tiny.help
echo "
USAGE
tiny [-u --user <username>]
[-r --repo <repository>]
[-c --code <vanity code>]
[-o --open]
[-h --help]
tiny [-c --code] [-o --open] owned-repo/url
"
end
# Force tmux to assume the terminal supports 256 colours.
function tmux
command tmux -2 $argv
end
# vi-mode
Basic vi key bindings emulation for fish.
## Install
Add `vi-mode` to your list of fish plugins in your `config.fish`.
Example:
set fish_plugins autojump vi-mode
## Configuration
### Default mode
The default vi mode can be set by defining the variable `vi_mode_default` in
your `config.fish`.
If used, this variable must be set before loading `oh-my-fish`.
Its default value is `vi_mode_insert`.
To set normal mode as default:
set vi_mode_default vi_mode_normal
### Mode indicator
The mode indicator is stored in the variable `vi_mode`.
See the oh-my-fish theme `simplevi` for an example of integration of the
indicator into the prompt.
### User key bindings
User additional key bindings can be defined with the function
`vi_mode_user_key_bindings`. If used, this function must be defined before
loading `oh-my-fish`.
Example:
function vi_mode_user_key_bindings
bind \el suppress-autosuggestion
end
## Not implemented
- bind 2 vi-arg-digit
- bind y yank-direction
- bind g magic :-P
- bind ^a increment next number
- bind ^x decrement next number
- bind /?nN search (jk kind of does this)
- registers (maybe try to make sensible integration into X, like an
explicit yank with y goes to an X selection, while an implicit
delete with x etc. doesn't. "\* and "+ should natually go to the
appropriate X selection if possible)
- etc.
## Author
This mode has been created by [Ian Munsie][ian_github], the original file can
be found [here][original].
It has been adapted for oh-my-fish by [Sylvain Benner][syl_github].
[ian_github]: https://github.com/DarkStarSword
[original]: https://github.com/DarkStarSword/junk/blob/master/vi-mode.fish
[syl_github]: https://github.com/syl20bnr
# This script is part of the vi-mode plugin for fish
# author: Ian Munsie
# Adapted for oh-my-fish by Sylvain Benner
import sys
from functools import reduce
command = sys.argv[1]
direction = sys.argv[2]
new_pos = pos = int(sys.argv[3])
lineno = int(sys.argv[4]) - 1
cmdline_list = sys.argv[5:]
cmdline = '\n'.join(cmdline_list)
def start():
return (0, 0)
def end():
return (len(cmdline), -1)
class not_found(Exception): pass
def dir_0():
return (reduce(lambda a,b: a + len(b) + 1, cmdline_list[:lineno], 0), 0)
def dir_eol(): # end of line
before_len = reduce(lambda a,b: a + len(b) + 1, cmdline_list[:lineno], 0)
line_len = len(cmdline_list[lineno]) or 1
return (before_len + line_len, -1)
# These routines are all similar, they can probably be combined into one, but
# I'll make sure I get all working and understand the differences first
def dir_fnw(): # First Non-Whitespace
import re
len_before = reduce(lambda a,b: a + len(b) + 1, cmdline_list[:lineno], 0)
match = re.search('^\s*[^\s]', cmdline_list[lineno])
if not match:
return start()
return (len_before + match.end()-1, 0)
dir__ = dir_fnw # XXX: I always used _ as this, but turns out that might not be quite right
def _dir_w(regexp):
import re
searchpart = cmdline[pos:]
match = re.search(regexp, searchpart)
if not match:
return end()
return (pos + match.end()-1, 0)
def _dir_e(regexp):
import re
searchpart = cmdline[pos+1:]
match = re.search(regexp, searchpart)
if not match:
return end()
return (pos+2 + match.start(), -1)
def _dir_b(regexp):
import re
if pos == 0:
return start()
# Reverse the string instead of matching to right:
searchpart = cmdline[pos-1::-1]
match = re.search(regexp, searchpart)
if not match:
return start()
return (len(searchpart) - (match.start()+1), 0)
def _dir_ge(regexp):
import re
if pos == 0:
return start()
# Reverse the string instead of matching to right:
searchpart = cmdline[pos::-1]
match = re.search(regexp, searchpart)
if not match:
return start()
return (len(searchpart) - (match.end()), 0)
# Simple, but not inclusive enough:
# def dir_w(): return _dir_w(r'[^\w]\w')
# def dir_e(): return _dir_e(r'\w[^\w]')
# Slightly too inclusive, e.g. fi--sh matches both '-' characters, but should only match one:
_dir_w_regexp = r'[^\w][^\s]|\w[^\w\s]'
_dir_e_regexp = r'[^\s][^\w]|[^\w\s]\w'
_dir_W_regexp = r'\s[^\s]'
_dir_E_regexp = r'[^\s]\s'
def dir_w(): return _dir_w(_dir_w_regexp)
def dir_W(): return _dir_w(_dir_W_regexp)
def dir_e(): return _dir_e(_dir_e_regexp)
def dir_E(): return _dir_e(_dir_E_regexp)
def dir_b(): return _dir_b(_dir_e_regexp)
def dir_B(): return _dir_b(_dir_E_regexp)
def dir_ge(): return _dir_ge(_dir_w_regexp)
def dir_gE(): return _dir_ge(_dir_W_regexp)
def dir_cw(): return _dir_w(_dir_e_regexp)
def dir_cW(): return _dir_w(_dir_E_regexp)
def dir_h():
if pos: return (pos-1, 0)
return start()
def dir_l():
return (pos+1, 0)
def dir_t(char):
new_pos = cmdline.find(char, pos+1)
if new_pos < 0:
raise not_found
return (new_pos, -1)
def dir_T(char):
new_pos = cmdline.rfind(char, 0, pos)
if new_pos < 0:
raise not_found
return (new_pos+1, 0)
def dir_f(char): return (dir_t(char)[0]+1, -1)
def dir_F(char): return (dir_T(char)[0]-1, 0)
def cmd_delete():
dst_pos = dir(direction)
if dst_pos >= pos:
new_cmdline = cmdline[:pos] + cmdline[dst_pos:]
return (new_cmdline, pos)
new_cmdline = cmdline[:dst_pos] + cmdline[pos:]
return (new_cmdline, dst_pos)
def cmd_change():
# 'Special case: 'cw' and 'cW' are treated like 'ce' and 'cE' if the cursor
# is on a non-blank. This is because 'cw' is interpreted as change-word,
# and a word does not include the following white space.'
#
# Note: Even with this special case the behaviour does not quite match what
# vim actually does in practice - try with the cursor on punctuation, or on
# the last character in a word. Specifically, the behaviour of cw differs
# from ce when the cursor is already on the last character of a 'word', for
# vim's definition of word.
#
# Because of this, we use a special direction to handle this case.
global direction
if direction in 'wW' and not cmdline[pos].isspace():
direction = direction.replace('w', 'cw').replace('W', 'cW')
return cmd_delete()
def cmd_o():
above = '\n'.join(cmdline_list[:lineno + 1])
below = '\n'.join(cmdline_list[lineno + 1:])
return (above + '\n\n' + below, len(above)+1)
def cmd_O():
above = '\n'.join(cmdline_list[:lineno])
below = '\n'.join(cmdline_list[lineno:])
return (above + '\n\n' + below, len(above)+1)
def _dir_cmd_func(func):
(pos1, pos2) = (pos, dir(direction))
if pos2 < pos:
(pos1, pos2) = (pos2, pos1)
new_cmdline = cmdline[:pos1] + func(cmdline[pos1:pos2]) + cmdline[pos2:]
return (new_cmdline, pos1)
# XXX: automagic completion sometimes hides the results of changing the case in these commands:
def cmd_upper(): return _dir_cmd_func(str.upper)
def cmd_lower(): return _dir_cmd_func(str.lower)
def cmd_swapcase(): return _dir_cmd_func(str.swapcase)
def dir(d, cursor = False):
def validate(pos):
if pos < 0: return 0
if pos > len(cmdline): return len(cmdline)
return pos
a = ()
if ':' in d:
(d, a) = d.split(':', 1)
(new_pos, cursor_off) = globals()['dir_%s' % d](*a)
if cursor:
return validate(new_pos + cursor_off)
return validate(new_pos)
def cmd(c): return globals()['cmd_%s' % c]()
def cmd_normal():
return (None, dir(direction, True))
try:
(cmdline, new_pos) = cmd(command)
if cmdline is not None:
print ( cmdline )
except not_found:
new_pos = pos
print ( new_pos )
set_color normal
# vi:noexpandtab:sw=4:ts=4
#
# vi-mode for fish
# author: Ian Munsie
# Adapted for oh-my-fish by Sylvain Benner
#
# Requirements: fish 2.0+
# I'm thinking about changing these to separate out the colours from the text.
# I'm undecided on this though - when I support count arguments there may be
# some benefit from displaying the count here, but that would also make the
# size of these strings vary, which I'd rather not do...
set -l cn (set_color normal 2>/dev/null)
set -g vi_mode_normal (set_color blue 2>/dev/null)'n'$cn
set -g vi_mode_replace (set_color red 2>/dev/null)'r'$cn
set -g vi_mode_REPLACE (set_color --background=red 2>/dev/null)'R'$cn
set -g vi_mode_insert (set_color green 2>/dev/null)'i'$cn
set -g vi_mode_delete (set_color red 2>/dev/null)'d'$cn
set -g vi_mode_change (set_color yellow 2>/dev/null)'c'$cn
set -g vi_mode_g (set_color blue 2>/dev/null)'g'$cn
set -g vi_mode_lower (set_color blue 2>/dev/null)'u'$cn
set -g vi_mode_upper (set_color blue 2>/dev/null)'U'$cn
set -g vi_mode_swapcase (set_color blue 2>/dev/null)'~'$cn
set -g __vi_mode_undo_cmdline ''
set -g __vi_mode_undo_cmdline_pos 0
# default vi mode
if test -z $vi_mode_default
set -g vi_mode_default vi_mode_insert
end
# additional user key bindings go in vi_mode_user_key_bindings
function __vi_mode_user_key_bindings
if functions | grep "vi_mode_user_key_bindings" > /dev/null
vi_mode_user_key_bindings
end
end
function __vi_mode_direction_command
# commandline should always be last
set ret (python (dirname (status -f))/vi-mode-impl.py $argv[1] $argv[2] (commandline -C) (commandline -L) (commandline))
set new_pos $ret[-1]
set -e ret[-1] # Guessing that deleting last element is likely to be faster than deleting first
if test (count $ret) -gt 0
commandline -- $ret
end
commandline -C $new_pos
end
function __vi_mode_common_emacs -d "common key bindings for all vi-like modes that are identical to the emacs mode"
# Feel free to expand this list for anything that makes sense, this is just
# a couple of hand-picked ones that seemed useful and/or I use :)
bind \e\[A up-or-search
bind \e\[B down-or-search
bind -k down down-or-search
bind -k up up-or-search
bind \e\[C forward-char
bind \e\[D backward-char
bind -k right forward-char
bind -k left backward-char
bind \e\[H beginning-of-line
bind \e\[F end-of-line
# OS X SnowLeopard doesn't have these keys. Don't show an annoying error message.
bind -k home beginning-of-line 2> /dev/null
bind -k end end-of-line 2> /dev/null
bind \cl 'clear; commandline -f repaint'
bind \cd delete-or-exit
end
function __vi_mode_common -d "common key bindings for all vi-like modes"
__vi_mode_common_emacs
bind \e vi_mode_normal
# Can we put commandline into history when pressing ^C?
bind \cc '__vi_mode_save_cmdline; for i in (seq (count (commandline))); echo; end; commandline ""; vi_mode_insert'
bind \n "commandline -f execute; "$vi_mode_default
__vi_mode_user_key_bindings
end
function __vi_mode_common_insert -d "common key bindings for all insert vi-like modes"
__vi_mode_common
bind \e 'commandline -f backward-char; vi_mode_normal'
if functions -q vi_mode_user
vi_mode_user insert
end
end
function __vi_mode_bind_directions
__vi_mode $argv[1]
for direction in W w E e B b 0 _ h l
bind $direction "$argv[3]; __vi_mode_direction_command '$argv[1]' $direction; $argv[2]"
end
bind \$ "$argv[3]; __vi_mode_direction_command '$argv[1]' eol; $argv[2]"
bind \^ "$argv[3]; __vi_mode_direction_command '$argv[1]' fnw; $argv[2]"
for direction in f F t T
bind $direction "__vi_mode_bind_all '$argv[3]; __vi_mode_direction_command %q$argv[1]%q {$direction}:%k; $argv[2]'"
end
bind g "__vi_mode_bind_directions_g $argv"
end
function __vi_mode_bind_directions_g
for direction in e E
bind $direction "$argv[3]; __vi_mode_direction_command '$argv[1]' g$direction; $argv[2]"
end
end
function __vi_mode_bind_all
# There seems to be some magic that doesn't work properly without this:
bind '' self-insert
python -c "
command = '''$argv'''
for c in map(chr, range(0x20, 0x7f)):
q = '\"' # Enclose command in these
Q = '\'' # Other quote - for quotes inside command
if c == '\"':
l = r = r'\\%s' % c
(q, Q) = (Q, q) # Swap quotes
elif c in ['(', ')', '<', '>', ';', '|', '\'']:
l = r = r'\%s' % c
elif c == '\\\\':
l = r'\\\\'
r = r'\\\\\\\\'
elif c == '\$':
l = '\%s' % c
r = r\"'\%s'\" % c
else:
l = r = \"'%s'\" % c
print ( 'bind %s %s%s%s' % (l, q, command.replace('%k', r).replace('%q', Q), q))
" | .
end
function __vi_mode
# Is there a way to do this without eval?
# We really want something like a dictionary...
eval set -g vi_mode \$vi_mode_{$argv}
commandline -f repaint
end
function __vi_mode_replace
__vi_mode replace
bind --erase --all
__vi_mode_common
# backward-char should happen last, but only works if specified first
# (guess I should dig through the C code and figure out what is going
# on):
# __vi_mode_bind_all "commandline -f delete-char; commandline -i %k; commandline -f backward-char; vi_mode_normal"
__vi_mode_bind_all "__vi_mode_save_cmdline; commandline -f backward-char delete-char; commandline -i %k; vi_mode_normal"
if functions -q vi_mode_user
vi_mode_user replace
end
end
function __vi_mode_overwrite
__vi_mode REPLACE
bind --erase --all
__vi_mode_common_insert
__vi_mode_save_cmdline
__vi_mode_bind_all "commandline -f delete-char; commandline -i %k"
if functions -q vi_mode_user
vi_mode_user overwrite
end
end
function __vi_mode_save_cmdline
# Only vi style single level for now, patch to suppport vim style
# multi-level undo history welcome
set -g __vi_mode_undo_cmdline (commandline)
set -g __vi_mode_undo_cmdline_pos (commandline -C)
end
function __vi_mode_undo
set -l cmdline (commandline)
set -l pos (commandline -C)
commandline $__vi_mode_undo_cmdline
commandline -C $__vi_mode_undo_cmdline_pos
set -g __vi_mode_undo_cmdline $cmdline
set -g __vi_mode_undo_cmdline_pos $pos
end
function __vi_mode_g -d "vi-like key bindings for fish (commands starting with g)"
__vi_mode g
bind --erase --all
__vi_mode_bind_all 'vi_mode_normal'
__vi_mode_common
bind I '__vi_mode_save_cmdline; commandline -f beginning-of-line; vi_mode_insert'
# XXX: automagic completion sometimes hides the results of changing the case in these commands:
bind u '__vi_mode_bind_directions lower vi_mode_normal __vi_mode_save_cmdline'
bind U '__vi_mode_bind_directions upper vi_mode_normal __vi_mode_save_cmdline'
bind \~ '__vi_mode_bind_directions swapcase vi_mode_normal __vi_mode_save_cmdline'
# TODO: The rest of the g commands + directions.
__vi_mode_bind_directions_g normal vi_mode_normal ''
if functions -q vi_mode_user
vi_mode_user g
end
end
function vi_mode_normal -d "WIP vi-like key bindings for fish (normal mode)"
__vi_mode normal
bind --erase --all
# NOTE: bind '' self-insert seems to be required to allow the
# prompt to change, but we don't want unbound keys to be able to
# self-insert, so set the default binding, but bind everything to
# do nothing (which is wasteful, but seems to work):
__vi_mode_bind_all ''
__vi_mode_common
# Fish recently gained support for this, redirect to /dev/null so it
# doesn't fall over if running an old version of fish:
commandline -f suppress-autosuggestion 2>/dev/null
bind i '__vi_mode_save_cmdline; vi_mode_insert'
bind I '__vi_mode_save_cmdline; __vi_mode_direction_command normal fnw; vi_mode_insert'
bind a '__vi_mode_save_cmdline; commandline -f forward-char; vi_mode_insert'
bind A '__vi_mode_save_cmdline; commandline -f end-of-line; vi_mode_insert'
bind o '__vi_mode_save_cmdline; __vi_mode_direction_command o ""; vi_mode_insert'
bind O '__vi_mode_save_cmdline; __vi_mode_direction_command O ""; vi_mode_insert'
# Cool, these functions are pretty close to what I wanted:
# FIXME: Cursor not placed in correct position, but moving it prevents further searching
bind j down-or-search
bind k up-or-search
bind x '__vi_mode_save_cmdline; commandline -f delete-char'
bind D '__vi_mode_save_cmdline; commandline -f kill-line'
# bind Y 'commandline -f kill-whole-line yank'
bind P '__vi_mode_save_cmdline; commandline -f yank'
bind p '__vi_mode_save_cmdline; commandline -f yank forward-char' # Yes, this is reversed. Otherwise it does the wrong thing. Go figure.
bind C '__vi_mode_save_cmdline; commandline -f kill-line; vi_mode_insert'
bind S '__vi_mode_save_cmdline; commandline -f kill-whole-line; vi_mode_insert'
bind s '__vi_mode_save_cmdline; commandline -f delete-char; vi_mode_insert'
bind r __vi_mode_replace
bind R __vi_mode_overwrite
# XXX: The automagic completion sometimes displays the case from the
# command it wants to complete instead of the case actually on the
# commandline, so even though this works, it may not always appear to work.
# I'm not sure if I can do anything about that, I'll need to look at the
# code. Ideally I would turn off automagic completion whenever I'm not in
# insert mode.
bind \~ '__vi_mode_save_cmdline; commandline -f forward-char; __vi_mode_direction_command swapcase l'
__vi_mode_bind_directions normal vi_mode_normal ''
bind d '__vi_mode_bind_directions delete vi_mode_normal __vi_mode_save_cmdline'
bind c '__vi_mode_bind_directions change vi_mode_insert __vi_mode_save_cmdline'
# Override generic direction code for simple things that have a close
# match in fish's builtin commands, which should be faster:
bind h backward-char
bind l forward-char
bind 0 beginning-of-line
# bind \$ end-of-line #FIXME: Cursor position
# bind b backward-word # Note: built-in implementation only recently fixed. Also, before enabling this override, determine if this matches on the right characters
bind g __vi_mode_g # MUST BE AFTER BIND_DIRECTIONS... I'm thinking about changing it so that this is all handled by bind_directions
bind u __vi_mode_undo
# NOT IMPLEMENTED:
# bind 2 vi-arg-digit
# bind y yank-direction
# bind g magic :-P
# bind ^a increment next number
# bind ^x decrement next number
# bind /?nN search (jk kind of does this)
# registers (maybe try to make sensible integration into X, like an
# explicit yank with y goes to an X selection, while an implicit
# delete with x etc. doesn't. "* and "+ should natually go to the
# appropriate X selection if possible)
# etc.
if functions -q vi_mode_user
vi_mode_user normal
end
end
function vi_mode_insert -d "vi-like key bindings for fish (insert mode)"
__vi_mode insert
fish_default_key_bindings
__vi_mode_common_insert
end
function fish_user_key_bindings
eval $vi_mode_default
end
# vi:noexpandtab:sw=4:ts=4
function vundle-init
if [ ! -d ~/.vim/bundle/vundle/ ]
mkdir -p ~/.vim/bundle/vundle/
end
if [ ! -d ~/.vim/bundle/vundle/.git/ ]
git clone http://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
echo "\n\tRead about vim configuration for vundle at https://github.com/gmarik/vundle\n"
end
end
function vundle
vundle-init
vim -c "execute \"BundleInstall\" | q | q"
end
function vundle-update
vundle-init
vim -c "execute \"BundleInstall!\" | q | q"
end
function vundle-clean
vundle-init
vim -c "execute \"BundleClean!\" | q | q"
end
# System
set -x XDG_DATA_DIRS /usr/share /usr/local/share
set -x XDG_CONFIG_DIRS /etc/xdg
# User
set -x XDG_CACHE_HOME $HOME/.cache
set -x XDG_CONFIG_HOME $HOME/.config
set -x XDG_DATA_HOME $HOME/.local/share
set -x XDG_DESKTOP_DIR $HOME/Desktop
set -x XDG_DOWNLOAD_DIR $HOME/Downloads
set -x XDG_DOCUMENTS_DIR $HOME/Documents
set -x XDG_MUSIC_DIR $HOME/Music
set -x XDG_PICTURES_DIR $HOME/Pictures
set -x XDG_VIDEOS_DIR $HOME/Videos
function z
cd (bash -c "source $Z_SCRIPT_PATH; _z $argv; echo \$PWD")
end
if test -z "$Z_SCRIPT_PATH"
set -gx 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 $Z_SCRIPT_PATH; _z --add `pwd -P`"
end
## agnoster
A ZSH theme optimized for people who use:
* Solarized
* Git
* Mercurial
* Unicode-compatible fonts and terminals (I use iTerm2 + Menlo)
For Mac users, I highly recommend iTerm 2 + Solarized Dark
![agnoster theme](https://f.cloud.github.com/assets/1765209/255379/452c668e-8c0b-11e2-8a8e-d1d13e57d15f.png)
#### Characteristics
* If the previous command failed (✘)
* User @ Hostname (if user is not DEFAULT_USER, which can then be set in your profile)
* Git status
* Mercurial status
* Branch () or detached head (➦)
* Current branch / SHA1 in detached head state
* Dirty working directory (±, color change)
* Working directory
* Elevated (root) privileges (⚡)
Ported from https://gist.github.com/agnoster/3712874.
# name: Agnoster
# agnoster's Theme - https://gist.github.com/3712874
# A Powerline-inspired theme for FISH
#
# # README
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://gist.github.com/1595572).
## Set this options in your config.fish (if you want to :])
# set -g theme_display_user yes
# set -g default_user your_normal_user
set -g current_bg NONE
set segment_separator \uE0B0
set right_segment_separator \uE0B0
# ===========================
# Helper methods
# ===========================
set -g __fish_git_prompt_showdirtystate 'yes'
set -g __fish_git_prompt_char_dirtystate '±'
set -g __fish_git_prompt_char_cleanstate ''
function parse_git_dirty
set -l submodule_syntax
set submodule_syntax "--ignore-submodules=dirty"
set git_dirty (command git status -s $submodule_syntax 2> /dev/null)
if [ -n "$git_dirty" ]
if [ $__fish_git_prompt_showdirtystate = "yes" ]
echo -n "$__fish_git_prompt_char_dirtystate"
end
else
if [ $__fish_git_prompt_showdirtystate = "yes" ]
echo -n "$__fish_git_prompt_char_cleanstate"
end
end
end
# ===========================
# Segments functions
# ===========================
function prompt_segment -d "Function to draw a segment"
set -l bg
set -l fg
if [ -n "$argv[1]" ]
set bg $argv[1]
else
set bg normal
end
if [ -n "$argv[2]" ]
set fg $argv[2]
else
set fg normal
end
if [ "$current_bg" != 'NONE' -a "$argv[1]" != "$current_bg" ]
set_color -b $bg
set_color $current_bg
echo -n "$segment_separator "
set_color -b $bg
set_color $fg
else
set_color -b $bg
set_color $fg
echo -n " "
end
set current_bg $argv[1]
if [ -n "$argv[3]" ]
echo -n -s $argv[3] " "
end
end
function prompt_finish -d "Close open segments"
if [ -n $current_bg ]
set_color -b normal
set_color $current_bg
echo -n "$segment_separator "
end
set -g current_bg NONE
end
# ===========================
# Theme components
# ===========================
function prompt_virtual_env -d "Display Python virtual environment"
if test "$VIRTUAL_ENV"
prompt_segment white black (basename $VIRTUAL_ENV)
end
end
function prompt_user -d "Display actual user if different from $default_user"
if [ "$theme_display_user" = "yes" ]
if [ "$USER" != "$default_user" -o -n "$SSH_CLIENT" ]
set USER_PROMPT (whoami)@(hostname)
prompt_segment black yellow $USER_PROMPT
end
end
end
function prompt_dir -d "Display the actual directory"
prompt_segment blue black (prompt_pwd)
end
function prompt_hg -d "Display mercurial state"
set -l branch
set -l state
if command hg id >/dev/null 2>&1
if command hg prompt >/dev/null 2>&1
set branch (command hg prompt "{branch}")
set state (command hg prompt "{status}")
set branch_symbol \uE0A0
if [ "$state" = "!" ]
prompt_segment red white "$branch_symbol $branch ±"
else if [ "$state" = "?" ]
prompt_segment yellow black "$branch_symbol $branch ±"
else
prompt_segment green black "$branch_symbol $branch"
end
end
end
end
function prompt_git -d "Display the actual git state"
set -l ref
set -l dirty
if command git rev-parse --is-inside-work-tree >/dev/null 2>&1
set dirty (parse_git_dirty)
set ref (command git symbolic-ref HEAD 2> /dev/null)
set ref (command git symbolic-ref HEAD 2> /dev/null)
if [ $status -gt 0 ]
set -l branch (command git show-ref --head -s --abbrev |head -n1 2> /dev/null)
set ref "➦ $branch "
end
set branch_symbol \uE0A0
set -l branch (echo $ref | sed "s-refs/heads/-$branch_symbol -")
if [ "$dirty" != "" ]
prompt_segment yellow black "$branch $dirty"
else
prompt_segment green black "$branch $dirty"
end
end
end
function prompt_status -d "the symbols for a non zero exit status, root and background jobs"
if [ $RETVAL -ne 0 ]
prompt_segment black red "✘"
end
# if superuser (uid == 0)
set -l uid (id -u $USER)
if [ $uid -eq 0 ]
prompt_segment black yellow "⚡"
end
# Jobs display
if [ (jobs -l | wc -l) -gt 0 ]
prompt_segment black cyan "⚙"
end
end
# ===========================
# Apply theme
# ===========================
function fish_prompt
set -g RETVAL $status
prompt_status
prompt_virtual_env
prompt_user
prompt_dir
prompt_hg
prompt_git
prompt_finish
end
## agnoster
A ZSH theme optimized for people who use:
* Solarized
* Git
* Unicode-compatible fonts and terminals (I use iTerm2 + Menlo)
For Mac users, I highly recommend iTerm 2 + Solarized Dark
![agnoster theme](https://f.cloud.github.com/assets/1765209/255379/452c668e-8c0b-11e2-8a8e-d1d13e57d15f.png)
#### Characteristics
* If the previous command failed (✘)
* User @ Hostname (if user is not DEFAULT_USER, which can then be set in your profile)
* Git status
* Branch () or detached head (➦)
* Current branch / SHA1 in detached head state
* Dirty working directory (±, color change)
* Working directory
* Elevated (root) privileges (⚡)
Ported from https://gist.github.com/agnoster/3712874.
# name: Agnoster
# agnoster's Theme - https://gist.github.com/3712874
# A Powerline-inspired theme for FISH
#
# # README
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://gist.github.com/1595572).
## Set this options in your config.fish (if you want to :])
# set -g theme_display_user yes
# set -g default_user your_normal_user
set -g current_bg NONE
set segment_separator \uE0B0
set right_segment_separator \uE0B0
# ===========================
# Helper methods
# ===========================
set -g __fish_git_prompt_showdirtystate 'yes'
set -g __fish_git_prompt_char_dirtystate '±'
set -g __fish_git_prompt_char_cleanstate ''
function parse_git_dirty
set -l submodule_syntax
set submodule_syntax "--ignore-submodules=dirty"
set git_dirty (command git status -s $submodule_syntax 2> /dev/null)
if [ -n "$git_dirty" ]
if [ $__fish_git_prompt_showdirtystate = "yes" ]
echo -n "$__fish_git_prompt_char_dirtystate"
end
else
if [ $__fish_git_prompt_showdirtystate = "yes" ]
echo -n "$__fish_git_prompt_char_cleanstate"
end
end
end
# ===========================
# Segments functions
# ===========================
function prompt_segment -d "Function to draw a segment"
set -l bg
set -l fg
if [ -n "$argv[1]" ]
set bg $argv[1]
else
set bg normal
end
if [ -n "$argv[2]" ]
set fg $argv[2]
else
set fg normal
end
if [ "$current_bg" != 'NONE' -a "$argv[1]" != "$current_bg" ]
set_color -b $bg
set_color $current_bg
echo -n "$segment_separator "
set_color -b $bg
set_color $fg
else
set_color -b $bg
set_color $fg
echo -n " "
end
set current_bg $argv[1]
if [ -n "$argv[3]" ]
echo -n -s $argv[3] " "
end
end
function prompt_finish -d "Close open segments"
if [ -n $current_bg ]
set_color -b normal
set_color $current_bg
echo -n "$segment_separator "
end
set -g current_bg NONE
end
# ===========================
# Theme components
# ===========================
function prompt_user -d "Display actual user if different from $default_user"
if [ "$theme_display_user" = "yes" ]
if [ "$USER" != "$default_user" -o -n "$SSH_CLIENT" ]
set USER_PROMPT (whoami)@(hostname)
prompt_segment black yellow $USER_PROMPT
end
end
end
function prompt_dir -d "Display the actual directory"
prompt_segment blue black (prompt_pwd)
end
function prompt_git -d "Display the actual git state"
set -l ref
set -l dirty
if command git rev-parse --is-inside-work-tree >/dev/null 2>&1
set dirty (parse_git_dirty)
set ref (command git symbolic-ref HEAD 2> /dev/null)
set ref (command git symbolic-ref HEAD 2> /dev/null)
if [ $status -gt 0 ]
set -l branch (command git show-ref --head -s --abbrev |head -n1 2> /dev/null)
set ref "➦ $branch "
end
set branch_symbol \uE0A0
set -l branch (echo $ref | sed "s-refs/heads/-$branch_symbol -")
if [ "$dirty" != "" ]
prompt_segment yellow black "$branch $dirty"
else
prompt_segment green black "$branch $dirty"
end
end
end
function prompt_status -d "the symbols for a non zero exit status, root and background jobs"
if [ $RETVAL -ne 0 ]
prompt_segment black red "✘"
end
# if superuser (uid == 0)
set -l uid (id -u $USER)
if [ $uid -eq 0 ]
prompt_segment black yellow "⚡"
end
# Jobs display
if [ (jobs -l | wc -l) -gt 0 ]
prompt_segment black cyan "⚙"
end
end
# ===========================
# Apply theme
# ===========================
function fish_prompt
set -g RETVAL $status
prompt_status
prompt_user
prompt_dir
prompt_git
prompt_finish
end
## beloglazov
A theme based on the default robbyrussell theme. This theme adds time, the
number of non-pushed commits, and whether the previous command has failed.
![beloglazov-fish-theme](https://raw.github.com/beloglazov/oh-my-fish/master/themes/beloglazov/beloglazov-fish-theme.png)
#### Characteristics
* Displays git information in the command prompt when available
* Displays the number of non-pushed git commits
* Displays the current time
* Displays ✘ if the previous command failed
# name: beloglazov
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 _git_ahead_count -a branch_name
echo (command git log origin/$branch_name..HEAD ^/dev/null | \
grep '^commit' | wc -l | tr -d ' ')
end
function fish_prompt
set -l last_status $status
set -l cyan (set_color -o cyan)
set -l yellow (set_color -o yellow)
set -l green (set_color green)
set -l red (set_color red)
set -l brightred (set_color -o red)
set -l blue (set_color -o blue)
set -l normal (set_color normal)
if [ $last_status != 0 ]
set failed "$brightred✘$normal "
end
if [ 'root' = (whoami) ]
set arrow "$brightred➜$normal "
else
set arrow ''
end
set -l time $red(date '+%I:%M')$normal
set -l cwd $cyan(basename (prompt_pwd))$normal
if [ (_git_branch_name) ]
set -l git_branch_name (_git_branch_name)
set -l git_branch $brightred$git_branch_name$normal
set git_info "$blue ($git_branch$blue)$normal"
set -l git_ahead_count (_git_ahead_count $git_branch_name)
if [ $git_ahead_count != 0 ]
set -l ahead_count "$green+$git_ahead_count$normal"
set git_info "$git_info $ahead_count"
end
if [ (_is_git_dirty) ]
set -l dirty "$yellow ✗$normal"
set git_info "$git_info$dirty"
end
end
echo -n -s $failed $arrow $time ' ' $cwd $git_info $normal ' '
end
## bira
Theme imported from Oh my ZSH: https://github.com/robbyrussell/oh-my-zsh/blob/master/themes/bira.zsh-theme
Contains traces of nuts and code from other Oh my fish themes.
Display username, hostname, current path, ruby version and git status. Display the latest error status in the right prompt.
![bira theme](https://cloud.githubusercontent.com/assets/1214238/5441541/8bd494dc-8491-11e4-9dbe-256b7e558eac.png)
TODO:
- display Python version
# Theme based on Bira theme from oh-my-zsh: https://github.com/robbyrussell/oh-my-zsh/blob/master/themes/bira.zsh-theme
# Some code stolen from oh-my-fish clearance theme: https://github.com/bpinto/oh-my-fish/blob/master/themes/clearance/
function __user_host
set -l content
if [ (id -u) = "0" ];
echo -n (set_color --bold red)
else
echo -n (set_color --bold green)
end
echo -n $USER@(hostname|cut -d . -f 1) (set color normal)
end
function __current_path
echo -n (set_color --bold blue) (pwd) (set_color normal)
end
function _git_branch_name
echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
end
function _git_is_dirty
echo (command git status -s --ignore-submodules=dirty ^/dev/null)
end
function __git_status
if [ (_git_branch_name) ]
set -l git_branch (_git_branch_name)
if [ (_git_is_dirty) ]
set git_info '<'$git_branch"*"'>'
else
set git_info '<'$git_branch'>'
end
echo -n (set_color yellow) $git_info (set_color normal)
end
end
function __ruby_version
if type "rvm-prompt" > /dev/null
set ruby_version (rvm-prompt i v g)
else if type "rbenv" > /dev/null
set ruby_version (rbenv version-name)
else
set ruby_version "system"
end
echo -n (set_color red) ‹$ruby_version› (set_color normal)
end
function fish_prompt
echo -n (set_color white)"╭─"(set_color normal)
__user_host
__current_path
__ruby_version
__git_status
echo -e ''
echo (set_color white)"╰─"(set_color --bold white)"\$ "(set_color normal)
end
function fish_right_prompt
set -l st $status
if [ $st != 0 ];
echo (set_color red) ↵ $st(set_color normal)
end
end
The MIT License (MIT)
Copyright (c) 2013-2014 Justin Hileman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
## bobthefish
bobthefish is a Powerline-style, Git-aware fish theme optimized for awesome.
![bobthefish][screenshot]
You will probably need a [Powerline-patched font][patching] for this to work.
[I recommend picking one of these][fonts].
This theme is based loosely on [agnoster][agnoster].
### Features
* A helpful, but not too distracting, greeting.
* A subtle timestamp hanging out off to the right.
* Powerline-style visual hotness.
* More colors than you know what to do with.
* An abbreviated path which doesn't abbreviate the name of the current project.
* All the things you need to know about Git in a glance.
* Visual indication that you can't write to the current directory.
### The Prompt
* Flags:
* Previous command failed (!)
* Background jobs (%)
* You currently have superpowers ($)
* User@Host (unless you're the default user)
* Current RVM or rbenv (Ruby) version
* Current virtualenv (Python) version
* Abbreviated parent directory
* Current directory, or Git or Mercurial project name
* Current project's repo branch ( master) or detached head (➦ d0dfd9b)
* Git or Mercurial status, via colors and flags:
* Dirty working directory (*)
* Untracked files (…)
* Staged changes (~)
* Stashed changes ($)
* Unpulled commits (-)
* Unpushed commits (+)
* Unpulled *and* unpushed commits (±)
* _Note that not all of these have been implemented for hg yet :)_
* Abbreviated project-relative path
### Configuration
You can override some default options in your `config.fish`:
set -g theme_display_git no
set -g theme_display_hg yes
set -g theme_display_virtualenv no
set -g theme_display_ruby no
set -g theme_display_user yes
set -g default_user your_normal_user
[screenshot]: http://i.0x7f.us/bobthefish.png
[patching]: https://powerline.readthedocs.org/en/latest/fontpatching.html
[fonts]: https://github.com/Lokaltog/powerline-fonts
[agnoster]: https://gist.github.com/agnoster/3712874
function fish_greeting -d "what's up, fish?"
set_color $fish_color_autosuggestion[1]
uname -npsr
uptime
set_color normal
end
# name: bobthefish
#
# bobthefish is a Powerline-style, Git-aware fish theme optimized for awesome.
#
# You will probably need a Powerline-patched font for this to work:
#
# https://powerline.readthedocs.org/en/latest/fontpatching.html
#
# I recommend picking one of these:
#
# https://github.com/Lokaltog/powerline-fonts
#
# You can override some default options in your config.fish:
#
# set -g theme_display_git no
# set -g theme_display_git_untracked no
# set -g theme_display_hg yes
# set -g theme_display_virtualenv no
# set -g theme_display_ruby no
# set -g theme_display_user yes
# set -g default_user your_normal_user
set -g __bobthefish_current_bg NONE
# Powerline glyphs
set __bobthefish_branch_glyph \uE0A0
set __bobthefish_ln_glyph \uE0A1
set __bobthefish_padlock_glyph \uE0A2
set __bobthefish_right_black_arrow_glyph \uE0B0
set __bobthefish_right_arrow_glyph \uE0B1
set __bobthefish_left_black_arrow_glyph \uE0B2
set __bobthefish_left_arrow_glyph \uE0B3
# Additional glyphs
set __bobthefish_detached_glyph \u27A6
set __bobthefish_nonzero_exit_glyph '! '
set __bobthefish_superuser_glyph '$ '
set __bobthefish_bg_job_glyph '% '
set __bobthefish_hg_glyph \u263F
# Python glyphs
set __bobthefish_superscript_glyph \u00B9 \u00B2 \u00B3
set __bobthefish_virtualenv_glyph \u25F0
set __bobthefish_pypy_glyph \u1D56
# Colors
set __bobthefish_lt_green addc10
set __bobthefish_med_green 189303
set __bobthefish_dk_green 0c4801
set __bobthefish_lt_red C99
set __bobthefish_med_red ce000f
set __bobthefish_dk_red 600
set __bobthefish_ruby_red af0000
set __bobthefish_slate_blue 255e87
set __bobthefish_med_blue 005faf
set __bobthefish_lt_orange f6b117
set __bobthefish_dk_orange 3a2a03
set __bobthefish_dk_grey 333
set __bobthefish_med_grey 999
set __bobthefish_lt_grey ccc
set __bobthefish_dk_brown 4d2600
set __bobthefish_med_brown 803F00
set __bobthefish_lt_brown BF5E00
# ===========================
# Helper methods
# ===========================
# function __bobthefish_in_git -d 'Check whether pwd is inside a git repo'
# command which git > /dev/null 2>&1; and command git rev-parse --is-inside-work-tree >/dev/null 2>&1
# end
# function __bobthefish_in_hg -d 'Check whether pwd is inside a hg repo'
# command which hg > /dev/null 2>&1; and command hg stat > /dev/null 2>&1
# end
function __bobthefish_git_branch -d 'Get the current git branch (or commitish)'
set -l ref (command git symbolic-ref HEAD ^/dev/null)
if [ $status -gt 0 ]
set -l branch (command git show-ref --head -s --abbrev | head -n1 ^/dev/null)
set ref "$__bobthefish_detached_glyph $branch"
end
echo $ref | sed "s#refs/heads/#$__bobthefish_branch_glyph #"
end
function __bobthefish_hg_branch -d 'Get the current hg branch'
set -l branch (command hg branch ^/dev/null)
set -l book " @ "(command hg book | grep \* | cut -d\ -f3)
echo "$__bobthefish_branch_glyph $branch$book"
end
function __bobthefish_pretty_parent -d 'Print a parent directory, shortened to fit the prompt'
echo -n (dirname $argv[1]) | sed -e 's#/private##' -e "s#^$HOME#~#" -e 's#/\(\.\{0,1\}[^/]\)\([^/]*\)#/\1#g' -e 's#/$##'
end
function __bobthefish_git_project_dir -d 'Print the current git project base directory'
[ "$theme_display_git" = 'no' ]; and return
command git rev-parse --show-toplevel ^/dev/null
end
function __bobthefish_hg_project_dir -d 'Print the current hg project base directory'
[ "$theme_display_hg" = 'yes' ]; or return
set d (pwd)
while not [ $d = / ]
if [ -e $d/.hg ]
command hg root --cwd "$d" ^/dev/null
return
end
set d (dirname $d)
end
end
function __bobthefish_project_pwd -d 'Print the working directory relative to project root'
echo "$PWD" | sed -e "s#$argv[1]##g" -e 's#^/##'
end
# ===========================
# Segment functions
# ===========================
function __bobthefish_start_segment -d 'Start a prompt segment'
set -l bg $argv[1]
set -e argv[1]
set -l fg $argv[1]
set -e argv[1]
set_color normal # clear out anything bold or underline...
set_color -b $bg
set_color $fg $argv
if [ "$__bobthefish_current_bg" = 'NONE' ]
# If there's no background, just start one
echo -n ' '
else
# If there's already a background...
if [ "$bg" = "$__bobthefish_current_bg" ]
# and it's the same color, draw a separator
echo -n "$__bobthefish_right_arrow_glyph "
else
# otherwise, draw the end of the previous segment and the start of the next
set_color $__bobthefish_current_bg
echo -n "$__bobthefish_right_black_arrow_glyph "
set_color $fg $argv
end
end
set __bobthefish_current_bg $bg
end
function __bobthefish_path_segment -d 'Display a shortened form of a directory'
if [ -w "$argv[1]" ]
__bobthefish_start_segment $__bobthefish_dk_grey $__bobthefish_med_grey
else
__bobthefish_start_segment $__bobthefish_dk_red $__bobthefish_lt_red
end
set -l directory
set -l parent
switch "$argv[1]"
case /
set directory '/'
case "$HOME"
set directory '~'
case '*'
set parent (__bobthefish_pretty_parent "$argv[1]")
set parent "$parent/"
set directory (basename "$argv[1]")
end
[ "$parent" ]; and echo -n -s "$parent"
set_color fff --bold
echo -n "$directory "
set_color normal
end
function __bobthefish_finish_segments -d 'Close open prompt segments'
if [ -n $__bobthefish_current_bg -a $__bobthefish_current_bg != 'NONE' ]
set_color -b normal
set_color $__bobthefish_current_bg
echo -n "$__bobthefish_right_black_arrow_glyph "
set_color normal
end
set -g __bobthefish_current_bg NONE
end
# ===========================
# Theme components
# ===========================
function __bobthefish_prompt_status -d 'Display symbols for a non zero exit status, root and background jobs'
set -l nonzero
set -l superuser
set -l bg_jobs
# Last exit was nonzero
if [ $status -ne 0 ]
set nonzero $__bobthefish_nonzero_exit_glyph
end
# if superuser (uid == 0)
set -l uid (id -u $USER)
if [ $uid -eq 0 ]
set superuser $__bobthefish_superuser_glyph
end
# Jobs display
if [ (jobs -l | wc -l) -gt 0 ]
set bg_jobs $__bobthefish_bg_job_glyph
end
set -l status_flags "$nonzero$superuser$bg_jobs"
if [ "$nonzero" -o "$superuser" -o "$bg_jobs" ]
__bobthefish_start_segment fff 000
if [ "$nonzero" ]
set_color $__bobthefish_med_red --bold
echo -n $__bobthefish_nonzero_exit_glyph
end
if [ "$superuser" ]
set_color $__bobthefish_med_green --bold
echo -n $__bobthefish_superuser_glyph
end
if [ "$bg_jobs" ]
set_color $__bobthefish_slate_blue --bold
echo -n $__bobthefish_bg_job_glyph
end
set_color normal
end
end
function __bobthefish_prompt_user -d 'Display actual user if different from $default_user'
if [ "$theme_display_user" = 'yes' ]
if [ "$USER" != "$default_user" -o -n "$SSH_CLIENT" ]
__bobthefish_start_segment $__bobthefish_lt_grey $__bobthefish_slate_blue
echo -n -s (whoami) '@' (hostname | cut -d . -f 1) ' '
end
end
end
function __bobthefish_prompt_hg -d 'Display the actual hg state'
set -l dirty (command hg stat; or echo -n '*')
set -l flags "$dirty"
[ "$flags" ]; and set flags ""
set -l flag_bg $__bobthefish_lt_green
set -l flag_fg $__bobthefish_dk_green
if [ "$dirty" ]
set flag_bg $__bobthefish_med_red
set flag_fg fff
end
__bobthefish_path_segment $argv[1]
__bobthefish_start_segment $flag_bg $flag_fg
echo -n -s $__bobthefish_hg_glyph ' '
__bobthefish_start_segment $flag_bg $flag_fg --bold
echo -n -s (__bobthefish_hg_branch) $flags ' '
set_color normal
set -l project_pwd (__bobthefish_project_pwd $argv[1])
if [ "$project_pwd" ]
if [ -w "$PWD" ]
__bobthefish_start_segment 333 999
else
__bobthefish_start_segment $__bobthefish_med_red $__bobthefish_lt_red
end
echo -n -s $project_pwd ' '
end
end
function __bobthefish_prompt_git -d 'Display the actual git state'
set -l dirty (command git diff --no-ext-diff --quiet --exit-code; or echo -n '*')
set -l staged (command git diff --cached --no-ext-diff --quiet --exit-code; or echo -n '~')
set -l stashed (command git rev-parse --verify --quiet refs/stash >/dev/null; and echo -n '$')
set -l ahead (command git rev-list --left-right '@{upstream}...HEAD' ^/dev/null | awk '/>/ {a += 1} /</ {b += 1} {if (a > 0) nextfile} END {if (a > 0 && b > 0) print "±"; else if (a > 0) print "+"; else if (b > 0) print "-"}')
set -l new ''
set -l show_untracked (git config --bool bash.showUntrackedFiles)
if [ "$theme_display_git_untracked" != 'no' -a "$show_untracked" != 'false' ]
set new (command git ls-files --other --exclude-standard)
[ "$new" ]; and set new '…'
end
set -l flags "$dirty$staged$stashed$ahead$new"
[ "$flags" ]; and set flags " $flags"
set -l flag_bg $__bobthefish_lt_green
set -l flag_fg $__bobthefish_dk_green
if [ "$dirty" -o "$staged" ]
set flag_bg $__bobthefish_med_red
set flag_fg fff
else if [ "$stashed" ]
set flag_bg $__bobthefish_lt_orange
set flag_fg $__bobthefish_dk_orange
end
__bobthefish_path_segment $argv[1]
__bobthefish_start_segment $flag_bg $flag_fg --bold
echo -n -s (__bobthefish_git_branch) $flags ' '
set_color normal
set -l project_pwd (__bobthefish_project_pwd $argv[1])
if [ "$project_pwd" ]
if [ -w "$PWD" ]
__bobthefish_start_segment 333 999
else
__bobthefish_start_segment $__bobthefish_med_red $__bobthefish_lt_red
end
echo -n -s $project_pwd ' '
end
end
function __bobthefish_prompt_dir -d 'Display a shortened form of the current directory'
__bobthefish_path_segment "$PWD"
end
function __bobthefish_virtualenv_python_version -d 'Get current python version'
set -l python_version (readlink (which python))
switch "$python_version"
case 'python2*'
echo $__bobthefish_superscript_glyph[2]
case 'python3*'
echo $__bobthefish_superscript_glyph[3]
case 'pypy*'
echo $__bobthefish_pypy_glyph
end
end
function __bobthefish_prompt_virtualfish -d "Display activated virtual environment (only for virtualfish, virtualenv's activate.fish changes prompt by itself)"
[ "$theme_display_virtualenv" = 'no' -o -z "$VIRTUAL_ENV" ]; and return
set -l version_glyph (__bobthefish_virtualenv_python_version)
if [ "$version_glyph" ]
__bobthefish_start_segment $__bobthefish_med_blue $__bobthefish_lt_grey
echo -n -s $__bobthefish_virtualenv_glyph $version_glyph
end
__bobthefish_start_segment $__bobthefish_med_blue $__bobthefish_lt_grey --bold
echo -n -s (basename "$VIRTUAL_ENV") ' '
set_color normal
end
function __bobthefish_prompt_rubies -d 'Display current Ruby (rvm/rbenv)'
[ "$theme_display_ruby" = 'no' ]; and return
set -l ruby_version
if type rvm-prompt >/dev/null 2>&1
set ruby_version (rvm-prompt i v g)
else if type rbenv >/dev/null 2>&1
set ruby_version (rbenv version-name)
# Don't show global ruby version...
[ "$ruby_version" = (rbenv global) ]; and return
end
[ -z "$ruby_version" ]; and return
__bobthefish_start_segment $__bobthefish_ruby_red $__bobthefish_lt_grey --bold
echo -n -s $ruby_version ' '
set_color normal
end
# ===========================
# Apply theme
# ===========================
function fish_prompt -d 'bobthefish, a fish theme optimized for awesome'
__bobthefish_prompt_status
__bobthefish_prompt_user
__bobthefish_prompt_rubies
__bobthefish_prompt_virtualfish
set -l git_root (__bobthefish_git_project_dir)
set -l hg_root (__bobthefish_hg_project_dir)
if [ (echo "$hg_root" | wc -c) -gt (echo "$git_root" | wc -c) ]
__bobthefish_prompt_hg $hg_root
else if [ "$git_root" ]
__bobthefish_prompt_git $git_root
else
__bobthefish_prompt_dir
end
__bobthefish_finish_segments
end
function fish_right_prompt -d 'bobthefish is all about the right prompt'
set_color $fish_color_autosuggestion[1]
date
set_color normal
end
function fish_title
echo $_ ' '
pwd
end
\ No newline at end of file
# Budspencer theme
A theme for the 70s, makes fish even more powerful. It's equipped with a hell
of a lot of nice functions and key bindings to speed up your workflow.
The philosophy behind budspencer theme:
* Delimit the prompt lines clearly to the output.
* Produce output only if it contains relevant information.
* Show useful notifications within the prompt.
* Equip the prompt with toggle commands in order to change its style
interactively.
* Store sessions in order to make frequently used commands quickly accessible.
* Make navigation within the directory tree as easy as possible using
bookmarks and a directory history without duplicates.
* Make histories quickly accessible with menus.
* Don't stress your eyes. Use different colors in dark and bright environments.
## Demonstration video
[![video][screenshot]](http://vimeo.com/105546618)
## Requirements
You need an up-to-date fish shell version from [github][fish-git] or a
[nightly build][fish-nightly].
Non standard tools:
* xsel
* wmctrl
* git
* [taskwarrior][taskwarrior] (optional)
* [remind][remind] (optional)
## Configuration
### General configuration
The theme behaves similar to vim's airline/powerline plugins. Thus, it needs a
[powerline font][font].
It's also crucial to have vi mode enabled. Thus, execute
```
set -U fish_key_bindings fish_vi_key_bindings
```
before enabling the theme.
### Colors
Redefine `$budspencer_colors` with the `set` command in order to change the
colors of the prompt.
Example:
```
set budspencer_colors 000000 333333 666666 ffffff ffff00 ff6600 ff0000 ff0033 3300ff 0000ff 00ffff
00ff00
```
will result in a prompt like this:
![color replace example][colors]
Two color schemes for bright and dark environments are predefined. You can
enable them with `day` and `night`, respectively.
### Command history
Commands that shouldn't appear in the command history are defined by a universal
list `$budspencer_nocmdhist`. Default:
```
set -U budspencer_nocmdhist c d ll ls m s
```
### Disable/reenable greeting
Disable:
```
set -U budspencer_nogreeting
```
Reenable:
```
set -e budspencer_nogreeting
```
## Outer prompt segments
- Vi mode is indicated by color of outer segments, cursor color also changes
if terminal supports it:
* blue: NORMAL mode
* yellow: INSERT mode
* magenta: VISUAL mode
## Left prompt segments
- Prompt line number
- Git repository information
- Status symbols
* ✻: keep track of this shell session, can be toggled with `#` to show the number of
the session within the sessions list
* ⌘: present working directory is in bookmark list, can be toggled with `#` to
show the number of the bookmark
* V: vi is parent process
* R: [ranger][ranger] is parent process
* ⚙: there are background jobs, can be toggled with `#` to show the amount of
background jobs
* : no write permissions in present working directory
* ⚔: there are tasks scheduled for this week, can be toggled with `#` to
show the amount of weekly tasks
* ⚑: there are appointments for today, can be toggled with `#` to
show the amount of appointments
* ✔: last command succeeded, can be toggled with `#` to show the status value
* ✘: last command failed, can be toggled with `#` to show the status value
* ⚡: superuser indicator
- Present working directory
## Right prompt segments
- Last command's duration time
- Git status symbols:
* ↑: git repository is ahead origin
* ↓: git repository is behind origin
* +: changes have been added to git index
* –: files have been deleted in work tree
* ✱: files have been modified in work tree
* →: files have been renamed in git index
* ═: there are unmerged commits
* ●: there are untracked (new) files
* ✭: there are stashed commits
## Toggle prompt segments
The following shortcuts need vi-mode:
- Style of "present working directory"-segment can be toggled in NORMAL and in
VISUAL mode with space bar
* styles implemented:
- `short` (shows username, short hostname and truncated path; recommended in
most cases)
- `long` (shows username, full hostname and full path; useful for copy-paste
in ssh connections)
- `none` (shows nothing except small delimiter; useful for small terminals)
- If prompt is toggled with `#`, the IP address is shown instead of the
hostname.
* configurable by universal list `$budspencer_pwdstyle` (if not set, defaults to
`short long none`); note that changes to `$budspencer_pwdstyle` keep persistant as it's
a universal variable.
![pwd style][pwdstyle]
- Style of symbols can be toggled in NORMAL and in VISUAL mode with `#`
* styles implemented:
- `symbols` (shows status symbols)
- `numbers` (shows numbers instead of symbols in left prompt as well as amount of changes in
right git prompt)
Note, the format is _username@hostname:pathname_. Thus, you can cut
the whole string with your mouse and paste it into `ssh` commands.
## Quickly navigate in history of working directories
The function `d` drops down a menu showing the history as enumerated list. Unlike
fish's builtin `dirh`, `d` does not show any duplicates. Enter a number to jump
to a directory within the list.
![dir menu][dirmenu]
The following shortcuts need vi-mode:
- Press `H` in NORMAL mode to change present working directory to previous
working directory in history.
- Press `L` in NORMAL mode to change present working directory to next working
directory in history.
## Quickly navigate in command history
The function `c` drops down a menu showing the command history as enumerated list similarly to
the `d` function. Selections are also pasted into the X clipboard. It's possible
to load a command of a former prompt by giving the prompt line number as
argument.
## Bookmarks
A bookmark can be created with `mark`. It can be removed with `unmark`.
Bookmarks are universal and thus persistant.
A new shell automatically changes working directory on startup to newest bookmark.
`m` is a function that drops down a menu showing the bookmarks as enumerated list
equivalently to `d`.
The following shortcuts need vi mode:
- Create a bookmark for present working directory with `m` in NORMAL mode.
- Remove a bookmark for present working directory with `M` in NORMAL mode.
## Edit commandline with your favorite editor
The function `edit-commandline` let you edit the commandline with your editor.
It makes the commandline as powerful as your editor. If `$EDITOR` is not set,
vi is used.
The following shortcut needs vi mode:
- Type `.` in NORMAL mode to edit commandline in editor.
## Sessions
Shell session can be stored with `s <session name>`. If a session with `session
name` already exists, the session with this name will be attached. If a session with
`session name` is already active within another terminal, this terminal will be
focussed.
A list of available sessions can be shown with `s`.
A session can be erased with `s -e <session name>`.
Type `s -d` to detach current session.
## Set window title
Just type `wt <title>`.
## TODO
- vi REPLACE mode, as soon as REPLACE mode is implemented within fish
## Feedback
Give me feedback if you ...
* ... have ideas how I could improve budspencer.
* ... have problems with budspencer.
* ... have questions concerning budspencer.
[font]: https://github.com/Lokaltog/powerline-fonts
[ranger]: http://ranger.nongnu.org/
[taskwarrior]: http://taskwarrior.org/
[remind]: http://www.roaringpenguin.com/products/remind
[fish-git]: https://github.com/fish-shell/fish-shell.git
[fish-nightly]: https://github.com/fish-shell/fish-shell/wiki/Nightly-builds
[screenshot]: https://raw.githubusercontent.com/tannhuber/media/master/budspencer.jpg
[colors]: https://raw.githubusercontent.com/tannhuber/media/master/budspencer_replace_colors.jpg
[dirmenu]: https://raw.githubusercontent.com/tannhuber/media/master/budspencer_dir_menu.jpg
[pwdstyle]: https://raw.githubusercontent.com/tannhuber/media/master/budspencer_pwd_style.jpg
###############################################################################
#
# prompt theme name:
# budspencer
#
# description:
# a sophisticated airline/powerline theme
#
# author:
# joseph tannhuber <sepp.tannhuber@yahoo.de>
#
# sections:
# -> Color definitions
# -> Functions
# -> Help
# -> Environment
# -> Window title
# -> Welcome message
#
###############################################################################
###############################################################################
# => Color definitions
###############################################################################
# Define colors
set -U budspencer_night 000000 083743 445659 fdf6e3 b58900 cb4b16 dc121f af005f 6c71c4 268bd2 2aa198 859900
set -U budspencer_day 000000 333333 666666 ffffff ffff00 ff6600 ff0000 ff0033 3300ff 00aaff 00ffff 00ff00
if not set -q budspencer_colors
# Values are: black dark_gray light_gray white yellow orange red magenta violet blue cyan green
set -U budspencer_colors $budspencer_night
end
# Cursor color changes according to vi-mode
# Define values for: normal_mode insert_mode visual_mode
set -U budspencer_cursors "\033]12;#$budspencer_colors[10]\007" "\033]12;#$budspencer_colors[5]\007" "\033]12;#$budspencer_colors[8]\007" "\033]12;#$budspencer_colors[9]\007"
# Some terminals cannot change the cursor color
set -l unsupported_terminals 'fbterm' 'st' 'linux' 'screen'
if contains $TERM $unsupported_terminals
set budspencer_cursors '' '' '' ''
end
###############################################################################
# => Functions
###############################################################################
#########
# => Help
#########
function budspencer_help -d 'Show helpfile'
set -l readme_file "$fish_path/themes/budspencer/README.md"
if set -q PAGER
if [ -e $readme_file ]
eval $PAGER $readme_file
else
set_color $fish_color_error[1]
echo "$readme_file wasn't found."
end
else
open $readme_file
end
end
################
# => Environment
################
function day -d "Set color palette for bright environment."
set budspencer_colors $budspencer_day
set budspencer_cursors "\033]12;#$budspencer_colors[10]\007" "\033]12;#$budspencer_colors[5]\007" "\033]12;#$budspencer_colors[8]\007" "\033]12;#$budspencer_colors[9]\007"
end
function night -d "Set color palette for dark environment."
set budspencer_colors $budspencer_night
set budspencer_cursors "\033]12;#$budspencer_colors[10]\007" "\033]12;#$budspencer_colors[5]\007" "\033]12;#$budspencer_colors[8]\007" "\033]12;#$budspencer_colors[9]\007"
end
#################
# => Window title
#################
function wt -d 'Set window title'
set -g window_title $argv
function fish_title
echo -n $window_title
end
end
####################
# => Welcome message
####################
function fish_greeting -d 'Show greeting in login shell.'
if not set -q budspencer_nogreeting
if begin
not set -q -x LOGIN
and not set -q -x RANGER_LEVEL
and not set -q -x VIM
end
echo This is (set_color -b $budspencer_colors[2] $budspencer_colors[10])budspencer(set_color normal) theme for fish, a theme for the 70s.
echo Type (set_color -b $budspencer_colors[2] $budspencer_colors[6])»budspencer_help«(set_color normal) in order to see how you can speed up your workflow.
end
end
end
###############################################################################
#
# Prompt theme name:
# budspencer
#
# Description:
# a sophisticated airline/powerline theme
#
# Author:
# Joseph Tannhuber <sepp.tannhuber@yahoo.de>
#
# Sections:
# -> Key bindings
# -> Files
# -> Functions
# -> Pre execute
# -> Directory history
# -> Command history
# -> Bookmarks
# -> Sessions
# -> Commandline editing with $EDITOR
# -> Git segment
# -> Bind-mode segment
# -> Symbols segment
# -> Prompt initialization
# -> Left prompt
#
###############################################################################
###############################################################################
# => Key bindings
###############################################################################
if [ $fish_key_bindings = 'fish_vi_key_bindings' ]
bind '#' __budspencer_toggle_symbols
bind -M visual '#' __budspencer_toggle_symbols
bind ' ' __budspencer_toggle_pwd
bind -M visual ' ' __budspencer_toggle_pwd
bind L __budspencer_cd_next
bind H __budspencer_cd_prev
bind m mark
bind M unmark
bind . __budspencer_edit_commandline
bind -M insert \n __budspencer_preexec
bind \n __budspencer_preexec
end
###############################################################################
# => Files
###############################################################################
# Config file
set -g budspencer_config "$HOME/.config/fish/budspencer_config.fish"
# Temporary files
set -g budspencer_tmpfile '/tmp/'(echo %self)'_budspencer_edit.fish'
###############################################################################
# => Functions
###############################################################################
################
# => Pre execute
################
function __budspencer_preexec -d 'Execute after hitting <Enter> before doing anything else'
set -l cmd (commandline | sed 's|\s\+|\x1e|g')
if [ $_ = 'fish' ]
if [ -z $cmd[1] ]
set -e cmd[1]
end
if [ -z $cmd[1] ]
return
end
set -e budspencer_prompt_error[1]
if not type -q $cmd[1]
if [ -d $cmd[1] ]
set budspencer_prompt_error (cd $cmd[1] ^&1)
and commandline ''
commandline -f repaint
return
end
end
switch $cmd[1]
case 'c'
if begin
[ (count $cmd) -gt 1 ]
and [ $cmd[2] -gt 0 ]
and [ $cmd[2] -lt $pcount ]
end
commandline $prompt_hist[$cmd[2]]
echo $prompt_hist[$cmd[2]] | xsel
commandline -f repaint
return
end
case 'cd'
if [ (count $cmd) -le 2 ]
set budspencer_prompt_error (eval $cmd ^&1)
and commandline ''
if [ (count $budspencer_prompt_error) -gt 1 ]
set budspencer_prompt_error $budspencer_prompt_error[1]
end
commandline -f repaint
return
end
case 'day' 'night'
if [ (count $cmd) -eq 1 ]
eval $cmd
commandline ''
commandline -f repaint
return
end
end
end
commandline -f execute
end
#####################
# => Fish termination
#####################
function __budspencer_on_termination -s HUP -s INT -s QUIT -s TERM --on-process %self -d 'Execute when shell terminates'
set -l item (contains -i %self $budspencer_sessions_active_pid ^ /dev/null)
__budspencer_detach_session $item
end
######################
# => Directory history
######################
function __budspencer_create_dir_hist -v PWD -d 'Create directory history without duplicates'
if [ "$pwd_hist_lock" = false ]
if contains $PWD $$dir_hist
set -e $dir_hist[1][(contains -i $PWD $$dir_hist)]
end
set $dir_hist $$dir_hist $PWD
set -g dir_hist_val (count $$dir_hist)
end
end
function __budspencer_cd_prev -d 'Change to previous directory, press H in NORMAL mode.'
if [ $dir_hist_val -gt 1 ]
set dir_hist_val (expr $dir_hist_val - 1)
set pwd_hist_lock true
cd $$dir_hist[1][$dir_hist_val]
commandline -f repaint
end
end
function __budspencer_cd_next -d 'Change to next directory, press L in NORMAL mode.'
if [ $dir_hist_val -lt (count $$dir_hist) ]
set dir_hist_val (expr $dir_hist_val + 1)
set pwd_hist_lock true
cd $$dir_hist[1][$dir_hist_val]
commandline -f repaint
end
end
function d -d 'List directory history, jump to directory in list with d <number>'
set -l num_items (expr (count $$dir_hist) - 1)
if [ $num_items -eq 0 ]
set_color $fish_color_error[1]
echo 'Directory history is empty. '(set_color normal)'It will be created automatically'
return
end
for i in (seq $num_items)
if [ (expr \( $num_items - $i \) \% 2) -eq 0 ]
set_color normal
else
set_color $budspencer_colors[4]
end
echo '▶' (expr $num_items - $i)\t$$dir_hist[1][$i] | sed "s|$HOME|~|"
end
if [ $num_items -eq 1 ]
set last_item ''
else
set last_item '-'(expr $num_items - 1)
end
echo -en $budspencer_cursors[2]
set input_length (expr length (expr $num_items - 1))
read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[5])" ♻ Goto [e|0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[5])' -n $input_length -l dir_num
switch $dir_num
case (seq 0 (expr $num_items - 1))
cd $$dir_hist[1][(expr $num_items - $dir_num)]
case 'e'
read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[5])" ♻ Erase [0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[5])' -n $input_length -l dir_num
set -e $dir_hist[1][(expr $num_items - $dir_num)] ^ /dev/null
set dir_hist_val (count $$dir_hist)
tput cuu1
end
for i in (seq (expr $num_items + 1))
tput cuu1
end
tput ed
tput cuu1
set pcount (expr $pcount - 1)
set no_prompt_hist 'T'
end
####################
# => Command history
####################
function __budspencer_create_cmd_hist -e fish_prompt -d 'Create command history without duplicates'
if [ $_ = 'fish' ]
set -l IFS ''
set -l cmd (echo $history[1] | fish_indent | expand -t 4)
# Create prompt history
if begin
[ $pcount -gt 0 ]
and [ $no_prompt_hist = 'F' ]
end
set prompt_hist[$pcount] $cmd
else
set no_prompt_hist 'F'
end
set pcount (expr $pcount + 1)
# Create command history
if not begin
expr $cmd : '[cdms] ' > /dev/null
or contains $cmd $budspencer_nocmdhist
end
if contains $cmd $$cmd_hist
set -e $cmd_hist[1][(contains -i $cmd $$cmd_hist)]
end
set $cmd_hist $$cmd_hist $cmd
end
end
set fish_bind_mode insert
echo -n \a
end
function c -d 'List command history, load command from prompt with c <prompt number>'
set -l num_items (count $$cmd_hist)
if [ $num_items -eq 0 ]
set_color $fish_color_error[1]
echo 'Command history is empty. '(set_color normal)'It will be created automatically.'
return
end
for i in (seq $num_items)
if [ (expr \( $num_items - $i \) \% 2) -eq 0 ]
set_color normal
else
set_color $budspencer_colors[4]
end
echo -n '▶ '(expr $num_items - $i)
set -l item (echo $$cmd_hist[1][$i])
echo -n \t$item\n
end
if [ $num_items -eq 1 ]
set last_item ''
else
set last_item '-'(expr $num_items - 1)
end
echo -en $budspencer_cursors[4]
set input_length (expr length (expr $num_items - 1))
read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[9])" ↩ Exec [e|0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[9])' -n $input_length -l cmd_num
switch $cmd_num
case (seq 0 (expr $num_items - 1))
commandline $$cmd_hist[1][(expr $num_items - $cmd_num)]
echo $$cmd_hist[1][(expr $num_items - $cmd_num)] | xsel
for i in (seq (count (echo $$cmd_hist\n)))
tput cuu1
end
case 'e'
read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[9])" ↩ Erase [0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[9])' -n $input_length -l cmd_num
for i in (seq (count (echo $$cmd_hist\n)))
tput cuu1
end
tput cuu1
set -e $cmd_hist[1][(expr $num_items - $cmd_num)] ^ /dev/null
end
tput ed
tput cuu1
set pcount (expr $pcount - 1)
set no_prompt_hist 'T'
end
##############
# => Bookmarks
##############
function mark -d 'Create bookmark for present working directory.'
if not contains $PWD $bookmarks
set -U bookmarks $PWD $bookmarks
set pwd_hist_lock true
commandline -f repaint
end
end
function unmark -d 'Remove bookmark for present working directory.'
if contains $PWD $bookmarks
set -e bookmarks[(contains -i $PWD $bookmarks)]
set pwd_hist_lock true
commandline -f repaint
end
end
function m -d 'List bookmarks, jump to directory in list with m <number>'
set -l num_items (count $bookmarks)
if [ $num_items -eq 0 ]
set_color $fish_color_error[1]
echo 'Bookmark list is empty. '(set_color normal)'Enter '(set_color $fish_color_command[1])'mark '(set_color normal)'in INSERT mode or '(set_color $fish_color_command[1])'m '(set_color normal)'in NORMAL mode, if you want to add the current directory to your bookmark list.'
return
end
for i in (seq $num_items)
if [ $PWD = $bookmarks[$i] ]
set_color $budspencer_colors[10]
else
if [ (expr \( $num_items - $i \) \% 2) -eq 0 ]
set_color normal
else
set_color $budspencer_colors[4]
end
end
echo '▶ '(expr $num_items - $i)\t$bookmarks[$i] | sed "s|$HOME|~|"
end
if [ $num_items -eq 1 ]
set last_item ''
else
set last_item '-'(expr $num_items - 1)
end
echo -en $budspencer_cursors[1]
set input_length (expr length (expr $num_items - 1))
read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[10])" ⌘ Goto [0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[10])' -n $input_length -l dir_num
switch $dir_num
case (seq 0 (expr $num_items - 1))
cd $bookmarks[(expr $num_items - $dir_num)]
end
for i in (seq (expr $num_items + 1))
tput cuu1
end
tput ed
tput cuu1
end
#############
# => Sessions
#############
function __budspencer_delete_zombi_sessions -d 'Delete zombi sessions'
for i in $budspencer_sessions_active_pid
if not contains $i %fish
set -l item (contains -i $i $budspencer_sessions_active_pid)
set -e budspencer_sessions_active_pid[$item]
set -e budspencer_sessions_active[$item]
end
end
end
function __budspencer_create_new_session -d 'Create a new session'
set -U budspencer_session_cmd_hist_$argv[1] $$cmd_hist
set -U budspencer_session_dir_hist_$argv[1] $$dir_hist
set -U budspencer_sessions $argv[1] $budspencer_sessions
end
function __budspencer_erase_session -d 'Erase current session'
if [ (count $argv) -eq 1 ]
set_color $fish_color_error[1]
echo 'Missing argument: name of session to erase'
return
end
if contains $argv[2] $budspencer_sessions_active
set_color $fish_color_error[1]
echo "Session '$argv[2]' cannot be erased because it's currently active."
return
end
if contains $argv[2] $budspencer_sessions
set -e budspencer_session_cmd_hist_$argv[2]
set -e budspencer_session_dir_hist_$argv[2]
set -e budspencer_sessions[(contains -i $argv[2] $budspencer_sessions)]
else
set_color $fish_color_error[1]
echo "Session '$argv[2]' not found. "(set_color normal)'Enter '(set_color $fish_color_command[1])'s '(set_color normal)'to show a list of all recorded sessions.'
end
end
function __budspencer_detach_session -d 'Detach current session'
set cmd_hist cmd_hist_nosession
set dir_hist dir_hist_nosession
if [ -z $$dir_hist ] ^ /dev/null
set $dir_hist $PWD
end
set dir_hist_val (count $$dir_hist)
set -e budspencer_sessions_active_pid[$argv] ^ /dev/null
set -e budspencer_sessions_active[$argv] ^ /dev/null
set budspencer_session_current ''
cd $$dir_hist[1][$dir_hist_val]
set no_prompt_hist 'T'
end
function __budspencer_attach_session -d 'Attach session'
set argv (echo -sn $argv\n | sed 's|[^[:alnum:]]|_|g')
if contains $argv[1] $budspencer_sessions_active
wmctrl -a "✻ $argv[1]"
else
wt "✻ $argv[1]"
__budspencer_detach_session $argv[-1]
set budspencer_sessions_active $budspencer_sessions_active $argv[1]
set budspencer_sessions_active_pid $budspencer_sessions_active_pid %self
set budspencer_session_current $argv[1]
if not contains $argv[1] $budspencer_sessions
__budspencer_create_new_session $argv[1]
end
set cmd_hist budspencer_session_cmd_hist_$argv[1]
set dir_hist budspencer_session_dir_hist_$argv[1]
if [ -z $$dir_hist ] ^ /dev/null
set $dir_hist $PWD
end
set dir_hist_val (count $$dir_hist)
cd $$dir_hist[1][$dir_hist_val] ^ /dev/null
end
set no_prompt_hist 'T'
end
function s -d 'Create, delete or attach session'
__budspencer_delete_zombi_sessions
if [ (count $argv) -eq 0 ]
set -l active_indicator
set -l num_items (count $budspencer_sessions)
if [ $num_items -eq 0 ]
set_color $fish_color_error[1]
echo -n 'Session list is empty. '
set_color normal
echo -n 'Enter '
set_color $fish_color_command[1]
echo -n 's '
set_color $fish_color_param[1]
echo -n 'session-name'
set_color normal
echo ' to record the current session.'
return
end
for i in (seq $num_items)
if [ $budspencer_sessions[$i] = $budspencer_session_current ]
set_color $budspencer_colors[8]
else
if [ (expr \( $num_items - $i \) \% 2) -eq 0 ]
set_color normal
else
set_color $budspencer_colors[4]
end
end
if contains $budspencer_sessions[$i] $budspencer_sessions_active
set active_indicator '✻ '
else
set active_indicator ' '
end
echo '▶ '(expr $num_items - $i)\t$active_indicator$budspencer_sessions[$i]
end
if [ $num_items -eq 1 ]
set last_item ''
else
set last_item '-'(expr $num_items - 1)
end
echo -en $budspencer_cursors[3]
set input_length (expr length (expr $num_items - 1))
read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[8])" ✻ Attach [e|0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[8])' -n $input_length -l session_num
set pcount (expr $pcount - 1)
switch $session_num
case (seq 0 (expr $num_items - 1))
set argv[1] $budspencer_sessions[(expr $num_items - $session_num)]
for i in (seq (expr $num_items + 1))
tput cuu1
end
tput ed
tput cuu1
case 'e'
read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[8])" ✻ Erase [0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[8])' -n $input_length -l session_num
if [ (expr $num_items - $session_num) -gt 0 ]
__budspencer_erase_session -e $budspencer_sessions[(expr $num_items - $session_num)]
end
for i in (seq (expr $num_items + 3))
tput cuu1
end
tput ed
return
case '*'
for i in (seq (expr $num_items + 1))
tput cuu1
end
tput ed
tput cuu1
return
end
end
set -l item (contains -i %self $budspencer_sessions_active_pid ^ /dev/null)
switch $argv[1]
case '-e'
__budspencer_erase_session $argv
case '-d'
wt 'fish'
__budspencer_detach_session $item
tput cuu1
tput ed
set pcount (expr $pcount - 1)
case '-*'
set_color $fish_color_error[1]
echo "Invalid argument: $argv[1]"
case '*'
__budspencer_attach_session $argv $item
end
end
#####################################
# => Commandline editing with $EDITOR
#####################################
function __budspencer_edit_commandline -d 'Open current commandline with your editor'
commandline > $budspencer_tmpfile
eval $EDITOR $budspencer_tmpfile
set -l IFS ''
if [ -s $budspencer_tmpfile ]
commandline (sed 's|^\s*||' $budspencer_tmpfile)
else
commandline ''
end
rm $budspencer_tmpfile
end
################
# => Git segment
################
function __budspencer_prompt_git_branch -d 'Return the current branch name'
set -l branch (command git symbolic-ref HEAD ^ /dev/null | sed -e 's|^refs/heads/||')
if not test $branch > /dev/null
set -l position (command git describe --contains --all HEAD ^ /dev/null)
if not test $position > /dev/null
set -l commit (command git rev-parse HEAD ^ /dev/null | sed 's|\(^.......\).*|\1|')
echo -n (set_color -b $budspencer_colors[11])''(set_color $budspencer_colors[1])' ➦ '$commit' '(set_color $budspencer_colors[11])
else
echo -n (set_color -b $budspencer_colors[9])''(set_color $budspencer_colors[1])'  '$position' '(set_color $budspencer_colors[9])
end
else
echo -n (set_color -b $budspencer_colors[3])''(set_color $budspencer_colors[1])'  '$branch' '(set_color $budspencer_colors[3])
end
end
######################
# => Bind-mode segment
######################
function __budspencer_prompt_bindmode -d 'Displays the current mode'
switch $fish_bind_mode
case default
set budspencer_current_bindmode_color $budspencer_colors[10]
echo -en $budspencer_cursors[1]
case insert
set budspencer_current_bindmode_color $budspencer_colors[5]
echo -en $budspencer_cursors[2]
if [ "$pwd_hist_lock" = true ]
set pwd_hist_lock false
__budspencer_create_dir_hist
end
case visual
set budspencer_current_bindmode_color $budspencer_colors[8]
echo -en $budspencer_cursors[3]
end
if [ (count $budspencer_prompt_error) -eq 1 ]
set budspencer_current_bindmode_color $budspencer_colors[7]
end
set_color -b $budspencer_current_bindmode_color $budspencer_colors[1]
echo -n " $pcount "
set_color -b $budspencer_colors[1] $budspencer_current_bindmode_color
end
####################
# => Symbols segment
####################
function __budspencer_prompt_left_symbols -d 'Display symbols'
set -l jobs (jobs | wc -l)
if [ -e ~/.taskrc ]
set todo (task due.before:sunday ^ /dev/null | tail -1 | cut -f1 -d' ')
set overdue (task due.before:today ^ /dev/null | tail -1 | cut -f1 -d' ')
end
if [ -e ~/.reminders ]
set appointments (rem -a | cut -f1 -d' ')
end
if [ (count $todo) -eq 0 ]
set todo 0
end
if [ (count $overdue) -eq 0 ]
set overdue 0
end
if [ (count $appointments) -eq 0 ]
set appointments 0
end
set_color -b $budspencer_colors[2]
echo -n ''
if [ $symbols_style = 'symbols' ]
if [ $budspencer_session_current != '' ]
set_color -o $budspencer_colors[8]
echo -n ' ✻'
end
if contains $PWD $bookmarks
set_color -o $budspencer_colors[10]
echo -n ' ⌘'
end
if set -q -x VIM
set_color -o $budspencer_colors[9]
echo -n ' V'
end
if set -q -x RANGER_LEVEL
set_color -o $budspencer_colors[9]
echo -n ' R'
end
if [ $jobs -gt 0 ]
set_color -o $budspencer_colors[11]
echo -n ' ⚙'
end
if [ ! -w . ]
set_color -o $budspencer_colors[6]
echo -n ' '
end
if [ $todo -gt 0 ]
set_color -o $budspencer_colors[4]
end
if [ $overdue -gt 0 ]
set_color -o $budspencer_colors[8]
end
if [ (expr $todo + $overdue) -gt 0 ]
echo -n ' ⚔'
end
if [ $appointments -gt 0 ]
set_color -o $budspencer_colors[5]
echo -n ' ⚑'
end
if [ $last_status -eq 0 ]
set_color -o $budspencer_colors[12]
echo -n ' ✔'
else
set_color -o $budspencer_colors[7]
echo -n ' ✘'
end
if [ $USER = 'root' ]
set_color -o $budspencer_colors[6]
echo -n ' ⚡'
end
else
if [ $budspencer_session_current != '' ] ^ /dev/null
set_color $budspencer_colors[8]
echo -n ' '(expr (count $budspencer_sessions) - (contains -i $budspencer_session_current $budspencer_sessions))
end
if contains $PWD $bookmarks
set_color $budspencer_colors[10]
echo -n ' '(expr (count $bookmarks) - (contains -i $PWD $bookmarks))
end
if set -q -x VIM
set_color -o $budspencer_colors[9]
echo -n ' V'
set_color normal
end
if set -q -x RANGER_LEVEL
set_color -b $budspencer_colors[2] $budspencer_colors[9]
echo -n ' '$RANGER_LEVEL
end
if [ $jobs -gt 0 ]
set_color -b $budspencer_colors[2] $budspencer_colors[11]
echo -n ' '$jobs
end
if [ ! -w . ]
set_color -o $budspencer_colors[6]
echo -n ' '
set_color normal
end
if [ $todo -gt 0 ]
set_color -b $budspencer_colors[2] $budspencer_colors[4]
end
if [ $overdue -gt 0 ]
set_color -b $budspencer_colors[2] $budspencer_colors[8]
end
if [ (expr $todo + $overdue) -gt 0 ]
echo -n " $todo"
end
if [ $appointments -gt 0 ]
set_color -b $budspencer_colors[2] $budspencer_colors[5]
echo -n " $appointments"
end
if [ $last_status -eq 0 ]
set_color -b $budspencer_colors[2] $budspencer_colors[12]
echo -n ' '$last_status
else
set_color -b $budspencer_colors[2] $budspencer_colors[7]
echo -n ' '$last_status
end
if [ $USER = 'root' ]
set_color -o $budspencer_colors[6]
echo -n ' ⚡'
end
end
echo -n ' '
set_color -b normal $budspencer_colors[2]
end
###############################################################################
# => Prompt initialization
###############################################################################
# Initialize some global variables
set -g budspencer_prompt_error
set -g budspencer_current_bindmode_color
set -U budspencer_sessions_active $budspencer_sessions_active
set -U budspencer_sessions_active_pid $budspencer_sessions_active_pid
set -g budspencer_session_current ''
set -g cmd_hist_nosession
set -g cmd_hist cmd_hist_nosession
set -g CMD_DURATION 0
set -g dir_hist_nosession
set -g dir_hist dir_hist_nosession
set -g pwd_hist_lock false
set -g pcount 1
set -g prompt_hist
set -g no_prompt_hist 'F'
set -g symbols_style 'symbols'
# Load user defined key bindings
if functions --query fish_user_key_bindings
fish_user_key_bindings
end
# Set favorite editor
if not set -q EDITOR
set -g EDITOR vi
end
# Source config file
if [ -e $budspencer_config ]
source $budspencer_config
end
# Don't save in command history
if not set -q budspencer_nocmdhist
set -U budspencer_nocmdhist 'c' 'd' 'll' 'ls' 'm' 's'
end
# Set PWD segment style
if not set -q budspencer_pwdstyle
set -U budspencer_pwdstyle short long none
end
set pwd_style $budspencer_pwdstyle[1]
# Cd to newest bookmark if this is a login shell
if not begin
set -q -x LOGIN
or set -q -x RANGER_LEVEL
or set -q -x VIM
end ^ /dev/null
cd $bookmarks[1]
end
set -x LOGIN $USER
###############################################################################
# => Left prompt
###############################################################################
function fish_prompt -d 'Write out the left prompt of the budspencer theme'
set -g last_status $status
echo -n -s (__budspencer_prompt_bindmode) (__budspencer_prompt_git_branch) (__budspencer_prompt_left_symbols) '' ' '
end
###############################################################################
#
# Prompt theme name:
# budspencer
#
# Description:
# a sophisticated airline/powerline theme
#
# Author:
# Joseph Tannhuber <sepp.tannhuber@yahoo.de>
#
# Sections:
# -> Functions
# -> Toggle functions
# -> Command duration segment
# -> Git segment
# -> PWD segment
# -> Prompt
#
###############################################################################
###############################################################################
# => Functions
###############################################################################
#####################
# => Toggle functions
#####################
function __budspencer_toggle_symbols -d 'Toggles style of symbols, press # in NORMAL or VISUAL mode'
if [ $symbols_style = 'symbols' ]
set symbols_style 'numbers'
else
set symbols_style 'symbols'
end
set pwd_hist_lock true
commandline -f repaint
end
function __budspencer_toggle_pwd -d 'Toggles style of pwd segment, press space bar in NORMAL or VISUAL mode'
for i in (seq (count $budspencer_pwdstyle))
if [ $budspencer_pwdstyle[$i] = $pwd_style ]
set pwd_style $budspencer_pwdstyle[(expr $i \% (count $budspencer_pwdstyle) + 1)]
set pwd_hist_lock true
commandline -f repaint
break
end
end
end
#############################
# => Command duration segment
#############################
function __budspencer_cmd_duration -d 'Displays the elapsed time of last command'
set -l seconds ''
set -l minutes ''
set -l hours ''
set -l days ''
set -l cmd_duration (expr $CMD_DURATION / 1000)
if [ $cmd_duration -gt 0 ]
set seconds (expr $cmd_duration \% 68400 \% 3600 \% 60)'s'
if [ $cmd_duration -ge 60 ]
set minutes (expr $cmd_duration \% 68400 \% 3600 / 60)'m'
if [ $cmd_duration -ge 3600 ]
set hours (expr $cmd_duration \% 68400 / 3600)'h'
if [ $cmd_duration -ge 68400 ]
set days (expr $cmd_duration / 68400)'d'
end
end
end
if [ $last_status -ne 0 ]
echo -n (set_color $budspencer_colors[2])''(set_color -b $budspencer_colors[2] $budspencer_colors[7])' '$days$hours$minutes$seconds
else
echo -n (set_color $budspencer_colors[2])''(set_color -b $budspencer_colors[2] $budspencer_colors[12])' '$days$hours$minutes$seconds
end
end
end
################
# => Git segment
################
function __budspencer_is_git_ahead_or_behind -d 'Check if there are unpulled or unpushed commits'
command git rev-list --count --left-right 'HEAD...@{upstream}' ^ /dev/null | sed 's|\s\+|\n|g'
end
function __budspencer_git_status -d 'Check git status'
set -l git_status (command git status --porcelain ^/dev/null | cut -c 1-2)
set -l added (echo -sn $git_status\n | egrep -c "[ACDMT][ MT]|[ACMT]D")
set -l deleted (echo -sn $git_status\n | egrep -c "[ ACMRT]D")
set -l modified (echo -sn $git_status\n | egrep -c ".[MT]")
set -l renamed (echo -sn $git_status\n | egrep -c "R.")
set -l unmerged (echo -sn $git_status\n | egrep -c "AA|DD|U.|.U")
set -l untracked (echo -sn $git_status\n | egrep -c "\?\?")
echo -n $added\n$deleted\n$modified\n$renamed\n$unmerged\n$untracked
end
function __budspencer_is_git_stashed -d 'Check if there are stashed commits'
command git log --format="%gd" -g $argv 'refs/stash' -- ^ /dev/null | wc -l
end
function __budspencer_prompt_git_symbols -d 'Displays the git symbols'
set -l is_repo (command git rev-parse --is-inside-work-tree ^/dev/null)
if [ -z $is_repo ]
return
end
set -l git_ahead_behind (__budspencer_is_git_ahead_or_behind)
set -l git_status (__budspencer_git_status)
set -l git_stashed (__budspencer_is_git_stashed)
if [ (expr $git_status[1] + $git_status[2] + $git_status[3] + $git_status[4] + $git_status[5] + $git_status[6] + $git_stashed) -ne 0 ]
set_color $budspencer_colors[3]
echo -n ''
set_color -b $budspencer_colors[3]
if [ $symbols_style = 'symbols' ]
if [ (count $git_ahead_behind) -eq 2 ]
if [ $git_ahead_behind[1] -gt 0 ]
set_color -o $budspencer_colors[5]
echo -n ' ↑'
end
if [ $git_ahead_behind[2] -gt 0 ]
set_color -o $budspencer_colors[5]
echo -n ' ↓'
end
end
if [ $git_status[1] -gt 0 ]
set_color -o $budspencer_colors[12]
echo -n ' +'
end
if [ $git_status[2] -gt 0 ]
set_color -o $budspencer_colors[7]
echo -n ' –'
end
if [ $git_status[3] -gt 0 ]
set_color -o $budspencer_colors[10]
echo -n ' ✱'
end
if [ $git_status[4] -gt 0 ]
set_color -o $budspencer_colors[8]
echo -n ' →'
end
if [ $git_status[5] -gt 0 ]
set_color -o $budspencer_colors[9]
echo -n ' ═'
end
if [ $git_status[6] -gt 0 ]
set_color -o $budspencer_colors[4]
echo -n ' ●'
end
if [ $git_stashed -gt 0 ]
set_color -o $budspencer_colors[11]
echo -n ' ✭'
end
else
if [ (count $git_ahead_behind) -eq 2 ]
if [ $git_ahead_behind[1] -gt 0 ]
set_color $budspencer_colors[5]
echo -n ' '$git_ahead_behind[1]
end
if [ $git_ahead_behind[2] -gt 0 ]
set_color $budspencer_colors[5]
echo -n ' '$git_ahead_behind[2]
end
end
if [ $git_status[1] -gt 0 ]
set_color $budspencer_colors[12]
echo -n ' '$git_status[1]
end
if [ $git_status[2] -gt 0 ]
set_color $budspencer_colors[7]
echo -n ' '$git_status[2]
end
if [ $git_status[3] -gt 0 ]
set_color $budspencer_colors[10]
echo -n ' '$git_status[3]
end
if [ $git_status[4] -gt 0 ]
set_color $budspencer_colors[8]
echo -n ' '$git_status[4]
end
if [ $git_status[5] -gt 0 ]
set_color $budspencer_colors[9]
echo -n ' '$git_status[5]
end
if [ $git_status[6] -gt 0 ]
set_color $budspencer_colors[4]
echo -n ' '$git_status[6]
end
if [ $git_stashed -gt 0 ]
set_color $budspencer_colors[11]
echo -n ' '$git_stashed
end
end
set_color -b $budspencer_colors[3] normal
end
end
################
# => PWD segment
################
function __budspencer_prompt_pwd -d 'Displays the present working directory'
set -l user_host ' '
if set -q SSH_CLIENT
if [ $symbols_style = 'symbols' ]
switch $pwd_style
case short
set user_host " $USER@"(hostname -s)':'
case long
set user_host " $USER@"(hostname -f)':'
end
else
set user_host " $USER@"(hostname -i)':'
end
end
set_color $budspencer_current_bindmode_color
echo -n ''
set_color normal
set_color -b $budspencer_current_bindmode_color $budspencer_colors[1]
if [ (count $budspencer_prompt_error) != 1 ]
switch $pwd_style
case short
echo -n $user_host(prompt_pwd)' '
case long
echo -n $user_host(pwd)' '
end
else
echo -n " $budspencer_prompt_error "
set -e budspencer_prompt_error[1]
end
set_color normal
end
###############################################################################
# => Prompt
###############################################################################
function fish_right_prompt -d 'Write out the right prompt of the budspencer theme'
echo -n (__budspencer_cmd_duration) (__budspencer_prompt_git_symbols) (__budspencer_prompt_pwd)
set_color normal
end
## cbjohnson theme
A minimal theme forked from the [yimmy][yimmy-commit] theme (thanks [jhillyerd][yimmy-author]!)
![screenshot](https://cloud.githubusercontent.com/assets/4823640/5327427/6f9e61bc-7d02-11e4-9223-38ddbed176c8.png)
[yimmy-commit]: https://github.com/bpinto/oh-my-fish/tree/3a4b7de689cabf3522227f51177a489d915c8b4d/themes/yimmy
[yimmy-author]: https://github.com/jhillyerd
function fish_prompt
# Cache exit status
set -l last_status $status
# Just calculate these once, to save a few cycles when displaying the prompt
if not set -q __fish_prompt_hostname
set -g __fish_prompt_hostname (hostname|cut -d . -f 1)
end
if not set -q __fish_prompt_char
switch (id -u)
case 0
set -g __fish_prompt_char \u276f\u276f
case '*'
set -g __fish_prompt_char »
end
end
# Setup colors
set -l normal (set_color normal)
set -l cyan (set_color cyan)
set -l yellow (set_color yellow)
set -l bpurple (set_color -o purple)
set -l bred (set_color -o red)
set -l bcyan (set_color -o cyan)
set -l bwhite (set_color -o white)
# Configure __fish_git_prompt
set -g __fish_git_prompt_show_informative_status true
set -g __fish_git_prompt_showcolorhints true
# Color prompt char red for non-zero exit status
set -l pcolor $bpurple
if [ $last_status -ne 0 ]
set pcolor $bred
end
# Top
echo -n $cyan$USER$normal at $yellow$__fish_prompt_hostname$normal in $bred(prompt_pwd)$normal
__fish_git_prompt
echo
# Bottom
echo -n $pcolor$__fish_prompt_char $normal
end
# Fish Theme: clearance
A minimalist [fish shell](http://fishshell.com/) theme for people who use git
![clearance theme](https://raw.github.com/cseelus/clearance-fish/master/clearance-fish_preview.png)
## Like it?
Check out other versions of this theme for OSX Terminal or VIM!
# name: clearance
# ---------------
# Based on idan. Display the following bits on the left:
# - Virtualenv name (if applicable, see https://github.com/adambrenecki/virtualfish)
# - Current directory name
# - Git branch and dirty state (if inside a git repo)
function _git_branch_name
echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
end
function _git_is_dirty
echo (command git status -s --ignore-submodules=dirty ^/dev/null)
end
function fish_prompt
set -l last_status $status
set -l cyan (set_color cyan)
set -l yellow (set_color yellow)
set -l red (set_color red)
set -l blue (set_color blue)
set -l green (set_color green)
set -l normal (set_color normal)
set -l cwd $blue(pwd | sed "s:^$HOME:~:")
# Output the prompt, left to right
# Add a newline before new prompts
echo -e ''
# Display [venvname] if in a virtualenv
if set -q VIRTUAL_ENV
echo -n -s (set_color -b cyan black) '[' (basename "$VIRTUAL_ENV") ']' $normal ' '
end
# Print pwd or full path
echo -n -s $cwd $normal
# Show git branch and status
if [ (_git_branch_name) ]
set -l git_branch (_git_branch_name)
if [ (_git_is_dirty) ]
set git_info '(' $yellow $git_branch "±" $normal ')'
else
set git_info '(' $green $git_branch $normal ')'
end
echo -n -s ' · ' $git_info $normal
end
set -l prompt_color $red
if test $last_status = 0
set prompt_color $normal
end
# Terminate with a nice prompt char
echo -e ''
echo -e -n -s $prompt_color '⟩ ' $normal
end
# Chris Morrell's Fish Theme
This is a theme I designed for myself but have given to a few friends and decided to publish for others' enjoyment.
![Chris Morrell's Fish Theme](https://cloud.githubusercontent.com/assets/21592/4770904/8a58e026-5b89-11e4-927c-42a387b41df0.gif)
## Features
- Minimal base prompt
- Shows compact git status w/ the number of changed files & current branch
- Gives a visual indication when you're logged in via SSH, or logged in as anyone
but the default user (set the `$default_user` variable to define your default user)
- Shows indicator if previous command failed
- Shows a bright red "!" if you're logged in as root
(Note: _This theme is designed for a light-on-dark theme like [Solarized](http://ethanschoonover.com/solarized) but should work in a dark-on-light terminal with a few terminal color tweaks_)
\ No newline at end of file
set -g pad " "
## Function to show a segment
function prompt_segment -d "Function to show a segment"
# Get colors
set -l bg $argv[1]
set -l fg $argv[2]
# Set 'em
set_color -b $bg
set_color $fg
# Print text
if [ -n "$argv[3]" ]
echo -n -s $argv[3]
end
end
## Function to show current status
function show_status -d "Function to show the current status"
if [ $RETVAL -ne 0 ]
prompt_segment red white " ▲ "
set pad ""
end
if [ -n "$SSH_CLIENT" ]
prompt_segment blue white " SSH: "
set pad ""
end
end
## Show user if not default
function show_user -d "Show user"
if [ "$USER" != "$default_user" -o -n "$SSH_CLIENT" ]
set -l host (hostname -s)
set -l who (whoami)
prompt_segment normal yellow " $who"
# Skip @ bit if hostname == username
if [ "$USER" != "$HOST" ]
prompt_segment normal white "@"
prompt_segment normal green "$host "
set pad ""
end
end
end
# Show directory
function show_pwd -d "Show the current directory"
set -l pwd (prompt_pwd)
prompt_segment normal blue "$pad$pwd "
end
# Show prompt w/ privilege cue
function show_prompt -d "Shows prompt with cue for current priv"
set -l uid (id -u $USER)
if [ $uid -eq 0 ]
prompt_segment red white " ! "
set_color normal
echo -n -s " "
else
prompt_segment normal white " \$ "
end
set_color normal
end
## SHOW PROMPT
function fish_prompt
set -g RETVAL $status
show_status
show_user
show_pwd
show_prompt
end
\ No newline at end of file
function get_git_status -d "Gets the current git status"
if command git rev-parse --is-inside-work-tree >/dev/null 2>&1
set -l dirty (command git status -s --ignore-submodules=dirty | wc -l | sed -e 's/^ *//' -e 's/ *$//' 2> /dev/null)
set -l ref (command git symbolic-ref HEAD | sed "s-refs/heads/--" | sed -e 's/^ *//' -e 's/ *$//' 2> /dev/null)
if [ "$dirty" != "0" ]
set_color -b normal
set_color red
echo "$dirty changed file"
if [ "$dirty" != "1" ]
echo "s"
end
echo " "
set_color -b red
set_color white
else
set_color -b cyan
set_color white
end
echo " $ref "
set_color normal
end
end
function fish_right_prompt -d "Prints right prompt"
get_git_status
end
\ No newline at end of file
# Fish Theme: coffeeandcode
Another theme choice for Oh-My-Fish! originally created by
[Jonathan Knapp](http://jonknapp.com).
![coffeeandcode](https://cloud.githubusercontent.com/assets/1272018/5966170/e846c75e-a7f9-11e4-8aeb-ebec4c974f5b.png)
### Warning:
This theme will overwrite all of your Fish color and git settings. If you'd like
to customize them, you will have to make changes to the `fish_prompt.fish` file
in this theme. All of the settings are listed at the top of the file.
# name: CoffeeAndCode
# Theme colors
set fish_color_normal 5f5f5f
set fish_color_command 5f87ff
set fish_color_quote brown
set fish_color_redirection normal
set fish_color_end bcbcbc
set fish_color_error red --bold
set fish_color_param 5f87ff
set fish_color_comment red
set fish_color_match cyan
set fish_color_search_match --background=purple
set fish_color_operator cyan
set fish_color_escape cyan
set fish_color_cwd 00875f
set fish_pager_color_prefix cyan
set fish_pager_color_completion normal
set fish_pager_color_description 555 yellow
set fish_pager_color_progress cyan
set fish_pager_color_secondary
set fish_color_host cyan
set fish_color_user cyan
# Git prompt setup
set __fish_git_prompt_char_untrackedfiles '*'
set __fish_git_prompt_color yellow
set __fish_git_prompt_color_stashstate red --bold
set __fish_git_prompt_showdirtystate true
set __fish_git_prompt_showstashstate true
set __fish_git_prompt_showuntrackedfiles true
function fish_prompt --description 'Write out the prompt'
set -l last_status $status
# Just calculate these once, to save a few cycles when displaying the prompt
if not set -q __fish_prompt_hostname
set -g __fish_prompt_hostname (hostname|cut -d . -f 1)
end
if not set -q __fish_prompt_normal
set -g __fish_prompt_normal (set_color normal)
end
function prompt_pwd
echo $PWD | sed -e "s|^$HOME|~|"
end
if not set -q -g __fish_classic_git_functions_defined
set -g __fish_classic_git_functions_defined
function __fish_repaint_user --on-variable fish_color_user --description "Event handler, repaint when fish_color_user changes"
if status --is-interactive
set -e __fish_prompt_user
commandline -f repaint ^/dev/null
end
end
function __fish_repaint_host --on-variable fish_color_host --description "Event handler, repaint when fish_color_host changes"
if status --is-interactive
set -e __fish_prompt_host
commandline -f repaint ^/dev/null
end
end
function __fish_repaint_status --on-variable fish_color_status --description "Event handler; repaint when fish_color_status changes"
if status --is-interactive
set -e __fish_prompt_status
commandline -f repaint ^/dev/null
end
end
end
set -l delim '$'
switch $USER
case root
if not set -q __fish_prompt_cwd
if set -q fish_color_cwd_root
set -g __fish_prompt_cwd (set_color $fish_color_cwd_root)
else
set -g __fish_prompt_cwd (set_color $fish_color_cwd)
end
end
case '*'
if not set -q __fish_prompt_cwd
set -g __fish_prompt_cwd (set_color $fish_color_cwd)
end
end
set -l prompt_status
if test $last_status -ne 0
if not set -q __fish_prompt_status
set -g __fish_prompt_status (set_color $fish_color_status)
end
set prompt_status "$__fish_prompt_status [$last_status]$__fish_prompt_normal"
end
if not set -q __fish_prompt_user
set -g __fish_prompt_user (set_color $fish_color_user)
end
if not set -q __fish_prompt_host
set -g __fish_prompt_host (set_color $fish_color_host)
end
echo -s "$__fish_prompt_user" "$USER" @ "$__fish_prompt_host" "$__fish_prompt_hostname" "$__fish_prompt_normal" ' ' "$__fish_prompt_cwd" (prompt_pwd)
echo -s (__fish_git_prompt) "$__fish_prompt_normal" "$delim" ' '
end
## cor
The name says it all
![cor theme](https://f.cloud.github.com/assets/516068/692075/a30d9080-dbf6-11e2-8dd3-d07cce41259d.png)
For this theme you need a emoji supporting terminal and the emoji-clock plugin
* emoji-clock
* Git
* Unicode-compatible fonts and terminals (I use iTerm2 on OSX)
#### Characteristics
##### Left side prompt
* If the previous command failed (✘)
* User @ Hostname
* Abbriviated path
* Emoji-clock
##### Right side prompt
* Branch
* Git status clean dirty (*)
* Time of last command
# name: Cor
# Display the following bits on the left:
# * Virtualenv name (if applicable, see https://github.com/adambrenecki/virtualfish)
# * Current user
# * Current compressed directory name
# * return status if not 0
function fish_prompt
set -l last_status $status
set -l yellow (set_color ffff33)
set -l dark_yellow (set_color ffb266)
set -l red (set_color red)
set -l green (set_color 80ff00)
set -l normal (set_color normal)
set -l dark_green (set_color 006600)
set -l cwd $cyan(basename (prompt_pwd))
# Prompt
set -l prompt
if [ "$UID" = "0" ]
set prompt "$red# "
else
set prompt "$normal% "
end
# output the prompt, left to right
# Add a newline before prompts
#echo -e ""
# Display [venvname] if in a virtualenv
if set -q VIRTUAL_ENV
echo -n -s (set_color -b cyan black) '[' (basename "$VIRTUAL_ENV") ']' $normal ' '
end
if test $last_status -ne 0
set ret_status $red $last_status '↵' $normal
end
# Display the current directory name
echo -n -s $green (whoami) $dark_green @ $green (hostname|cut -d . -f 1) $dark_green › $yellow (prompt_pwd) $ret_status $dark_yellow (emoji-clock) ' ⁑' $normal
#echo -n -s $green (whoami) $dark_green @ $green (hostname|cut -d . -f 1) $dark_green › $yellow (prompt_pwd) $ret_status $dark_yellow ⁑ $normal
# Terminate with a nice prompt char
echo -n -s ' ' $normal
end
# Display git branch and dirty bit and current time on the right
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_right_prompt
set -l cyan (set_color cyan)
set -l red (set_color red)
set -l normal (set_color normal)
set -l yellow (set_color cccc00)
set -l green (set_color 80ff00)
set -l pink (set_color ff99ff)
set -l dark_pink (set_color cc99ff)
# Show git branch and dirty state
if [ (_git_branch_name) ]
set -l git_branch (_git_branch_name)
if [ (_is_git_dirty) ]
echo -n -s $cyan '‹' $yellow $git_branch $red '*' $cyan '›' $normal
else
echo -n -s $cyan '‹' $yellow $git_branch $cyan '›' $normal
end
end
echo -n -s $pink ' [' $dark_pink (date +%H:%M:%S) $pink '] '
end
## robbyrussell
Based on the robbyrussell theme.
![robbyrussell theme](https://bachue.github.io/oh-my-fish/images/robbyrussell-screenshot.png)
#### Characteristics
* Displays git information in the command prompt when available.
* Indicates 'master' branch with a distinctive color, encouraging the use of feature-branches (useful when development is done using pull requests)
* If the last command was failed, the indicator would be red, otherwise it's green
# name: eclm
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 last_status $status
set -l cyan (set_color -o cyan)
set -l yellow (set_color -o yellow)
set -l red (set_color -o red)
set -l blue (set_color -o blue)
set -l green (set_color -o green)
set -l normal (set_color normal)
if test $last_status = 0
set arrow "$green➜ "
else
set arrow "$red➜ "
end
set -l cwd $cyan(basename (prompt_pwd))
if [ (_git_branch_name) ]
if test (_git_branch_name) = 'master'
set -l git_branch (_git_branch_name)
set git_info "$blue ($yellow$git_branch$blue)"
else
set -l git_branch (_git_branch_name)
set git_info "$blue ($git_branch)$blue"
end
if [ (_is_git_dirty) ]
set -l dirty "$yellow ✗"
set git_info "$git_info$dirty"
end
end
echo -n -s $arrow $cwd $git_info $normal ' '
end
## Theme Edan
Inspired by idan, a functional, uncluttered fish theme with usability perks for git users and python developers.
![Screenshot of theme Edan](https://cloud.githubusercontent.com/assets/215282/6199938/f67e6a54-b49a-11e4-800b-587a638cfb86.png)
#### Characteristics
##### Left Prompt
* User & host (Shown in "remote" mode, hidden by default. Execute `edan-set-remote` or `edan-set-local` to switch.)
* Current python virtualenv (if applicable)
* Truncated CWD (just the current folder name)
* Git branch and dirty state (if applicable)
##### Right Prompt
* Full CWD path
* Last error code (if applicable)
#### Font
Check out [Anonymous Pro](http://www.marksimonson.com/fonts/view/anonymous-pro).
# Switch environment to "local" for edan.
function edan-set-local
set -U EDAN_HOST_TYPE "local"
end
# Switch environment to "remote" for edan.
function edan-set-remote
set -U EDAN_HOST_TYPE 'remote'
end
# fish theme: edan
# Display the following bits on the left:
# * User & host (hidden by default, execute `edan-remote`to show, `edan-local` to hide)
# * Virtualenv name (if applicable, see https://github.com/adambrenecki/virtualfish)
# * Current directory name
# * Git branch and dirty state (if inside a git repo)
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 _user_host
if [ (id -u) = "0" ];
echo -n (set_color -o red)
else
echo -n (set_color -o blue)
end
echo -n (hostname|cut -d . -f 1)ˇ$USER (set color normal)
end
function fish_prompt
set fish_greeting
set -l cyan (set_color -o cyan)
set -l yellow (set_color -o yellow)
set -l red (set_color -o red)
set -l blue (set_color -o blue)
set -l green (set_color -o green)
set -l normal (set_color normal)
set -l cwd $cyan(basename (prompt_pwd))
# output the prompt, left to right
# Add a newline before prompts
echo -e ""
# Display [venvname] if in a virtualenv
if set -q VIRTUAL_ENV
echo -n -s (set_color -b cyan black) '[' (basename "$VIRTUAL_ENV") ']' $normal ' '
end
# Display [user & host] when on remote host
if [ "$EDAN_HOST_TYPE" = "remote" ]
_user_host; echo -n ': '
end
# Display the current directory name
echo -n -s $cwd $normal
# Show git branch and dirty state
if [ (_git_branch_name) ]
set -l git_branch '[' (_git_branch_name) ']'
if [ (_is_git_dirty) ]
set git_info $red $git_branch "×"
else
set git_info $green $git_branch
end
echo -n -s ' ' $git_info $normal
end
# Terminate with a nice prompt char
echo -n -s ' » ' $normal
end
# Display the compressed current working path on the right
# If the previous command returned any kind of error code, display that too
function fish_right_prompt
set -l last_status $status
set -l cyan (set_color -o cyan)
set -l red (set_color -o red)
set -l normal (set_color normal)
echo -n -s $cyan (prompt_pwd)
if test $last_status -ne 0
set_color red
printf ' %d' $last_status
set_color normal
end
end
## FishFace
Shows an ASCII fish which is blue or green when in a git repo.
![fishface theme](https://f.cloud.github.com/assets/66143/1224622/ec9660d8-2750-11e3-9c96-cb7a5a69eada.png)
# name: FishFace
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 blue (set_color -o blue)
set -l green (set_color -o green)
if [ (_git_branch_name) ]
echo -n -s "$green><(((\"> "
else
echo -n -s "$blue><(((\"> "
end
end
## fishy-drupal
![fishy-drupal](https://raw.github.com/greggles/fishy-drupal/master/drups-fish-theme.png)
#### Features
* Shows the present working directory, abbreviated (default fish style)
* Shows the active git branch, if any
* Shows the active drush site alias, if any
* Shows yellow ✗ if the current git directory is "dirty"
# name: fishy-drupal
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 _drush_alias_name
set -l pid %self
if test -f "$TMPDIR/drush-env/drush-drupal-site-$pid"
echo (command cat $TMPDIR/drush-env/drush-drupal-site-$pid)
end
end
function fish_prompt
set -l cyan (set_color -o cyan)
set -l yellow (set_color -o yellow)
set -l red (set_color -o red)
set -l blue (set_color -o blue)
set -l normal (set_color normal)
set -l arrow "$blue➜ "
set -l cwd (set_color $fish_color_cwd)(prompt_pwd)
if [ (_git_branch_name) ]
set -l git_branch $red(_git_branch_name)
set git_info "$blue git:($git_branch$blue)"
if [ (_is_git_dirty) ]
set -l dirty "$yellow ✗"
set git_dirty "$dirty"
end
end
if [ (_drush_alias_name) ]
set -l drush_alias $blue(_drush_alias_name)
set drush_info "$green drush:($drush_alias$green)"
end
echo -n -s $arrow $cwd $git_info $drush_info $git_dirty $normal ' '
end
# Fisk
![theme screenshot](https://cloud.githubusercontent.com/assets/20814/6209746/60949aa6-b5c9-11e4-8edc-5a8e370f4527.png)
A nice dark blue-green theme with support for:
- Last exit code
- Current git HEAD
- Current python virtualenv
By [joar](https://github.com/joar), thanks to
[adisbladis](https://github.com/adisbladis) for the starting point.
function _fisk_concat
for i in $argv
echo -n $i;
end
end
function fish_prompt --description 'Write out the prompt'
set last_ret $status
# Palette
set -l base01 55f
set -l base02 55a
set -l base03 777
set -l c_error f77
set -l c_success 7f7
set -l c_yellow ff5
set -l c_magenta f0d
# Just calculate these once, to save a few cycles when displaying the prompt
if not set -q __fish_prompt_hostname
set -g __fish_prompt_hostname (hostname|cut -d . -f 1)
end
if not set -q __fish_prompt_cwd
set -g __fish_prompt_cwd (set_color $fish_color_cwd)
end
if set -q VIRTUAL_ENV
set venv (_fisk_concat " " (set_color $c_magenta) "(" (basename "$VIRTUAL_ENV") ")" (set_color normal))
else
set venv ""
end
set ret_color $c_success
if test $last_ret -gt 0
set ret_color $c_error
end
set -l ret_part (_fisk_concat \
(set_color $base03) '[' \
(set_color $ret_color) $last_ret \
(set_color $base03) ']' \
)
set -l user_part (_fisk_concat \
(set_color $base01) $USER \
(set_color $base02) @ \
(set_color $base01) $__fish_prompt_hostname \
)
# Virtualenv, git, &c.
set -l context_part (_fisk_concat \
$__fish_prompt_cwd (prompt_pwd) $venv (set_color -o $c_yellow) (__fish_git_prompt) \
)
set -l prompt_end (_fisk_concat (set_color $base01) '➞')
echo -n (_fisk_concat $ret_part " " $user_part " " $context_part " " $prompt_end (set_color normal) " ")
end
## fox
cloned from oh-my-zsh.
![fox theme](http://i60.tinypic.com/2myaibn.jpg)
function fish_prompt
# Cache exit status
set -l last_status $status
# Just calculate these once, to save a few cycles when displaying the prompt
if not set -q __fish_prompt_hostname
set -g __fish_prompt_hostname (hostname|cut -d . -f 1)
end
if not set -q __fish_prompt_char
switch (id -u)
case 0
set -g __fish_prompt_char '#'
case '*'
set -g __fish_prompt_char '>'
end
end
# Setup colors
set -l normal (set_color normal)
set -l red (set_color red)
set -l cyan (set_color cyan)
set -l white (set_color white)
# Configure __fish_git_prompt
set -g __fish_git_prompt_char_stateseparator ' '
set -g __fish_git_prompt_color white
set -g __fish_git_prompt_color_flags red
set -g __fish_git_prompt_color_prefix cyan
set -g __fish_git_prompt_color_suffix cyan
set -g __fish_git_prompt_showdirtystate true
set -g __fish_git_prompt_showuntrackedfiles true
set -g __fish_git_prompt_showstashstate true
set -g __fish_git_prompt_show_informative_status true
# Line 1
echo -n $cyan'┌['$white$USER$cyan'@'$white$__fish_prompt_hostname$cyan']'$white'-'$cyan'('$white(prompt_pwd)$cyan')'
__fish_git_prompt "-[git://%s]-"
echo
# Line 2
echo -n $cyan'└'$__fish_prompt_char $normal
end
## Gianu
Original theme made by [gianu](https://github.com/gianu) for oh-my-zsh, converted to oh-my-fish by [JBarberU](https://github.com/JBarberU)
![gianu theme](https://cloud.githubusercontent.com/assets/1499062/5955321/114b64d2-a7a2-11e4-8732-e8cf06903314.png)
#### Characteristics
Displays:
* Username and hostname
* Working directory
* Git information when available.
# 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
## GitStatus
![GitStatus](https://github.com/godfat/fish_prompt-gitstatus/raw/master/gitstatus.png)
#### Characteristics
* Displays host information in the command prompt when connected via ssh.
* Displays git information in the command prompt when inside a git repository.
- Shows current branch name.
- Shows * if working copy is dirty.
- Shows # if everything is staged.
- Shows no indicators if the working copy is clean.
# name: GitStatus
# Find latest version from: https://github.com/godfat/fish_prompt-gitstatus
function _git_branch_name
echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
end
function _git_status_symbol
set -l git_status (git status --porcelain ^/dev/null)
if test -n "$git_status"
# Is there anyway to preserve newlines so we can reuse $git_status?
if git status --porcelain ^/dev/null | grep '^.[^ ]' >/dev/null
echo '*' # dirty
else
echo '#' # all staged
end
else
echo '' # clean
end
end
function _remote_hostname
if test -n "$SSH_CONNECTION"
echo (whoami)@(hostname)
end
end
function fish_prompt
set -l cyan (set_color cyan)
set -l normal (set_color normal)
set -l cwd (set_color $fish_color_cwd)(prompt_pwd)
set -l git_status (_git_status_symbol)(_git_branch_name)
if test -n "$git_status"
set git_status " $git_status"
end
echo -n (_remote_hostname) $cwd$cyan$git_status$normal'> '
end
# Fish Theme: gnuykeaj
Super minimal one line version of [clearance](https://github.com/bpinto/oh-my-fish/tree/master/themes/clearance) theme. Balance between need to know information and space. Has git branch and dirty state information based on the color of the branch name.
![gnuykjeatheme](https://raw.githubusercontent.com/andyklimczak/oh-my-fish/gnuykeaj-screenshot/themes/gnuykeaj/gnuykeaj-preview.png)
# name: gnuykeaj
# ---------------
# Based on clearance, which is based off idan.
# 1 line minimal, beautiful version of clearance.
# Display the following bits on the left:
# - Virtualenv name (if applicable, see https://github.com/adambrenecki/virtualfish)
# - Current directory name
# - Git branch and dirty state (if inside a git repo)
function _git_branch_name
echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
end
function _git_is_dirty
echo (command git status -s --ignore-submodules=dirty ^/dev/null)
end
function fish_prompt
set -l last_status $status
set -l cyan (set_color cyan)
set -l yellow (set_color yellow)
set -l red (set_color red)
set -l blue (set_color blue)
set -l green (set_color green)
set -l normal (set_color normal)
set -l cwd $blue(basename (pwd | sed "s:^$HOME:~:"))
# Display [venvname] if in a virtualenv
if set -q VIRTUAL_ENV
echo -n -s (set_color -b cyan black) '[' (basename "$VIRTUAL_ENV") ']' $normal ' '
end
# Print pwd or full path
echo -n -s $cwd $normal
# Show git branch and status
if [ (_git_branch_name) ]
set -l git_branch (_git_branch_name)
if [ (_git_is_dirty) ]
set git_info $yellow $git_branch "±" $normal
else
set git_info $green $git_branch $normal
end
echo -n -s ' · ' $git_info $normal
end
set -l prompt_color $red
if test $last_status = 0
set prompt_color $normal
end
# Terminate with a nice prompt char
echo -e -n -s $prompt_color ' ⟩ ' $normal
end
## godfather fish theme
Clean git theme with homey feel and git-centric features.
![screenshot](http://i.imgur.com/mh7a39d.png)
#### Prompt structure:
* Left-hand side:
* user@host:
* truncated cwd (just the current folder name)
* git branch with state info (if applicable)
* Right-hand side:
* last error code (if applicable)
* [timestamp]
#### Credits:
Colors and git functions taken from [amio](https://github.com/amio)'s
[edan](https://github.com/bpinto/oh-my-fish/tree/master/themes/edan) theme.
# fish theme: goddy
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
# change color depending on the user.
function _user_host
if [ (id -u) = "0" ];
echo -n (set_color -o red)
else
echo -n (set_color -o blue)
end
echo -n (hostname|cut -d . -f 1)ˇ$USER (set color normal)
end
function fish_prompt
set fish_greeting
set -l cyan (set_color -o cyan)
set -l yellow (set_color -o yellow)
set -l red (set_color -o red)
set -l blue (set_color -o blue)
set -l green (set_color -o green)
set -l normal (set_color normal)
set -l cwd $cyan(basename (prompt_pwd))
# output the prompt, left to right:
# display 'user@host:'
echo -n -s $green (whoami) $dark_green @ $green (hostname|cut -d . -f 1) ": "
# display the current directory name:
echo -n -s $cwd $normal
# show git branch and dirty state, if applicable:
if [ (_git_branch_name) ]
set -l git_branch '[' (_git_branch_name) ']'
if [ (_is_git_dirty) ]
set git_info $red $git_branch "×"
else
set git_info $green $git_branch
end
echo -n -s ' ' $git_info $normal
end
# terminate with a nice prompt char:
echo -n -s ' » ' $normal
end
# fish theme: godfather
function fish_right_prompt
set -l last_status $status
set -l cyan (set_color -o cyan)
set -l red (set_color -o red)
set -l normal (set_color normal)
# print last exit code if nonzero:
if test $last_status -ne 0
set_color red
printf '%d' $last_status
set_color normal
end
# display the timestamp on the utmost right.
echo -n -s $normal ' [' (date +%H:%M:%S) ']'
end
## idan
A functional, uncluttered fish theme with usability perks for git users and python developers.
![Screenshot of idan theme](https://f.cloud.github.com/assets/22723/544512/14b7cd6e-c251-11e2-82c0-d5b4f41581c7.png)
#### Characteristics
##### Left Prompt
* Current python virtualenv (if applicable)
* Truncated CWD (just the current folder name)
* Git branch and dirty state (if applicable)
##### Right Prompt
* Full CWD path
* Last error code (if applicable)
# name: idan
# Display the following bits on the left:
# * Virtualenv name (if applicable, see https://github.com/adambrenecki/virtualfish)
# * Current directory name
# * Git branch and dirty state (if inside a git repo)
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 -o cyan)
set -l yellow (set_color -o yellow)
set -l red (set_color -o red)
set -l blue (set_color -o blue)
set -l green (set_color -o green)
set -l normal (set_color normal)
set -l cwd $cyan(basename (prompt_pwd))
# output the prompt, left to right
# Add a newline before prompts
echo -e ""
# Display [venvname] if in a virtualenv
if set -q VIRTUAL_ENV
echo -n -s (set_color -b cyan black) '[' (basename "$VIRTUAL_ENV") ']' $normal ' '
end
# Display the current directory name
echo -n -s $cwd $normal
# Show git branch and dirty state
if [ (_git_branch_name) ]
set -l git_branch '(' (_git_branch_name) ')'
if [ (_is_git_dirty) ]
set git_info $red $git_branch " ★ "
else
set git_info $green $git_branch
end
echo -n -s ' · ' $git_info $normal
end
# Terminate with a nice prompt char
echo -n -s ' ⟩ ' $normal
end
# Display the compressed current working path on the right
# If the previous command returned any kind of error code, display that too
function fish_right_prompt
set -l last_status $status
set -l cyan (set_color -o cyan)
set -l red (set_color -o red)
set -l normal (set_color normal)
echo -n -s $cyan (prompt_pwd)
if test $last_status -ne 0
set_color red
printf ' %d' $last_status
set_color normal
end
end
# name: Integral
function _git_branch_name
echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
end
function _upstream_count
echo (command git rev-list --count --left-right origin/(_git_branch_name)...HEAD ^/dev/null)
end
function _git_up_info
if [ (_upstream_count) ]
set -l count (_upstream_count)
switch $count
case "" # no upstream
echo ''
case "0?0" # equal to upstream
echo ''
case "0??" # ahead of upstream
echo 'u+'(echo $count | cut -f2)
case "??0" # behind upstream
echo 'u-'(echo $count | cut -f1)
case '???' # diverged from upstream
echo $count 'u+'(echo $count | cut -f2)'-'(echo $count | cut -f1)
case '*'
echo ''
end
end
end
function _is_git_dirty
echo (command git status -s --ignore-submodules=dirty ^/dev/null)
end
function fish_prompt
set -l blue (set_color blue)
set -l yellow (set_color yellow)
set -l normal (set_color normal)
set -l green (set_color green)
set -l arrow "∫"
set -l cwd $blue(prompt_pwd)
if [ (_git_branch_name) ]
set -l git_branch (_git_branch_name)
set -l git_vs_upstream (_git_up_info)
if [ (_is_git_dirty) ]
set git_info $yellow'('$git_branch "±" "$git_vs_upstream"')' $normal
else if [ (_git_up_info) ]
set git_info $yellow'('$git_branch "$git_vs_upstream"')' $normal
else
set git_info $green'('$git_branch')' $normal
end
end
echo -n -s $cwd' '"$git_info" $normal $arrow ' '
end
function fish_right_prompt
set -l dark_gray (set_color 222)
echo -n -s $dark_gray ' ['(date +%H:%M:%S)'] '
end
## integral
A simple git upstream theme.
#### Characteristics
* Current branch
* Dirty working directory
* Working directory
* Git upstream status
#### Screenshot
![Integral Screenshot](https://cloud.githubusercontent.com/assets/21774/2715353/70af1520-c50a-11e3-9db3-74933fbb8d91.png)
## jacaetevha
A theme optimized for people who use:
* Git
* Unicode-compatible fonts and terminals (I use iTerm2 + Monaco)
For Mac users, I highly recommend iTerm 2.
![jacaetevha
theme](http://jacaetevha.github.io/oh-my-fish/screenshot.png)
#### Characteristics
* Left-hand prompt:
```
<user> at <host> in <abbreviated path> <total size of files in dir> (<current Git branch>)
```
* Right-hand prompt:
```
<current date>
```
# name: Jacaetevha
function tbytes -d 'calculates the total size of the files in the current directory'
set -l tBytes (ls -al | grep "^-" | awk 'BEGIN {i=0} { i += $5 } END { print i }')
if test $tBytes -lt 1048576
set -g total (echo -e "scale=3 \n$tBytes/1048 \nquit" | bc)
set -g units " Kb"
else
set -g total (echo -e "scale=3 \n$tBytes/1048576 \nquit" | bc)
set -g units " Mb"
end
echo -n "$total$units"
end
function fish_prompt
set_color yellow
printf '%s' (whoami)
set_color normal
printf ' at '
set_color magenta
printf '%s' (hostname|cut -d . -f 1)
set_color normal
printf ' in '
set_color $fish_color_cwd
printf '%s ' (prompt_pwd)
set_color blue
printf '%s' (tbytes)
set_color normal
printf '%s' (__fish_git_prompt)
# Line 2
echo
if test $VIRTUAL_ENV
printf "(%s) " (set_color blue)(basename $VIRTUAL_ENV)(set_color normal)
end
printf '↪ '
set_color normal
end
function fish_right_prompt -d "Write out the right prompt"
set_color yellow
date
set_color normal
end
## krisleech
A very simple ZSH theme optimized for Git. Less is more.
![krisleech theme](https://f.cloud.github.com/assets/66143/930316/732ea576-0008-11e3-964c-98410709d00c.png)
![krisleech theme](https://f.cloud.github.com/assets/66143/930317/73446046-0008-11e3-8ecb-2abec0058b83.png)
### Characteristics
* Current working directory
* Branch name
* Dirty working directory (✘)
# name: Krisleech
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 -o cyan)
set -l yellow (set_color -o yellow)
set -l red (set_color -o red)
set -l blue (set_color -o blue)
set -l green (set_color -o green)
set -l normal (set_color normal)
set -l cwd $cyan(basename (prompt_pwd))
if [ (_git_branch_name) ]
set -l git_branch (_git_branch_name)
set git_info "$green$git_branch "
if [ (_is_git_dirty) ]
set -l dirty "$yellow✗"
set git_info "$git_info$dirty"
end
end
echo -n -s $cwd $red '|' $git_info $normal ⇒ ' ' $normal
end
# name: L
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 blue (set_color blue)
set -l green (set_color green)
set -l normal (set_color normal)
set -l arrow "λ"
set -l cwd $blue(basename (prompt_pwd))
if [ (_git_branch_name) ]
set git_info $green(_git_branch_name)
set git_info ":$git_info"
if [ (_is_git_dirty) ]
set -l dirty "*"
set git_info "$git_info$dirty"
end
end
echo -n -s $cwd $git_info $normal ' ' $arrow ' '
end
# To show the right prompt please set
# set theme_display_rbenv 'yes' (config.fish)
# set theme_display_rbenv_gemset 'yes' (config.fish)
function _ruby_version
echo (command rbenv version-name | sed 's/\n//')
end
function _ruby_gemset
echo (command rbenv gemset active ^/dev/null | sed -e 's| global||')
end
function fish_right_prompt
if [ "$theme_display_rbenv" = 'yes' ]
set -l red (set_color red)
set -l normal (set_color normal)
set ruby_info $red(_ruby_version)
if [ "$theme_display_rbenv_gemset" = 'yes' ]
if [ (_ruby_gemset) ]
set -l ruby_gemset $red(_ruby_gemset)
set ruby_info "$ruby_info@$ruby_gemset"
end
end
echo -n -s $ruby_info $normal
end
end
## l
A theme inspired by [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh/blob/master/themes/lambda.zsh-theme)'s [lambda](http://zshthem.es/screenshots/lambda.png) theme.
![](http://f.cl.ly/items/2J3M0f2X1j3u471y080I/2.png)
![](http://f.cl.ly/items/2S25360U1p360E0D2u2g/3.png)
![](http://f.cl.ly/items/1w0s0Q3x3r2Z1F1l011k/4.png)
#### Characteristics
* Current branch
* Dirty working directory
* Working directory
Only if fish_theme_l_right_prompt variable is set true within config.fish
```fish
set theme_display_rbenv 'yes'
set theme_display_rbenv_gemset 'yes'
```
* Rbenv Ruby Version
* Rbenv Ruby Gemset
![](http://f.cl.ly/items/0f0k3o2L3y2q1L3g1R1X/5.png)
## mtahmed
Minimal theme.
![mtahmed](https://cloud.githubusercontent.com/assets/1272018/5965709/13d07f68-a7f6-11e4-9872-7936516ba258.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
# 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
# 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
## nai
A minimalist fish theme which displays git branch and status information.
![nai](https://cloud.githubusercontent.com/assets/1272018/5961225/116d0a7a-a7d3-11e4-88a6-43da003ddc6c.png)
#### Characteristics
##### Left Prompt
* Truncated CWD (just the current folder name)
* Git branch and dirty state (if applicable)
# name: nai
# Display the following bits on the left:
# * Current directory name
# * Git branch and dirty state (if inside a git repo)
function _git_branch_name
echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
end
function _git_dirty
echo (command git status -s --ignore-submodules=dirty ^/dev/null)
end
function fish_prompt
set -l yellow (set_color yellow)
set -l green (set_color green)
set -l normal (set_color normal)
set -l cwd (basename (prompt_pwd))
echo -e ""
echo -n -s ' ' $cwd $normal
if [ (_git_branch_name) ]
set -l git_branch (_git_branch_name)
if [ (_git_dirty) ]
set git_info $yellow $git_branch
else
set git_info $green $git_branch
end
echo -n -s ' ' $git_info $normal
end
echo -n -s ' ' $normal
end
# name: Numist
function fish_prompt
set -l last_status $status
# Colours
set -l cyan (set_color -o cyan)
set -l yellow (set_color -o yellow)
set -l green (set_color -o green)
set -l red (set_color -o red)
set -l blue (set_color -o blue)
set -l magenta (set_color magenta)
set -l white (set_color white)
set -l normal (set_color normal)
# Prints first argument left-aligned, second argument right-aligned, newline
function _rprint
if [ (count $argv) = 1 ]
echo -s $argv
else
set -l arglength (echo -n -s "$argv[1]$argv[2]" | perl -le 'while (<>) {
s/ \e[ #%()*+\-.\/]. |
(?:\e\[|\x9b) [ -?]* [@-~] | # CSI ... Cmd
(?:\e\]|\x9d) .*? (?:\e\\|[\a\x9c]) | # OSC ... (ST|BEL)
(?:\e[P^_]|[\x90\x9e\x9f]) .*? (?:\e\\|\x9c) | # (DCS|PM|APC) ... ST
\e.|[\x80-\x9f] //xg;
print;
}' | awk '{printf length;}')
set -l termwidth (tput cols)
set -l padding
if [ $arglength -lt $termwidth ]
set padding (printf "%0"(math $termwidth - $arglength)"d"|tr "0" " ")
end
echo -s "$argv[1]$padding$argv[2]"
end
end
# Unconditional stuff
set -l path $blue(pwd | sed "s:^$HOME:~:")
set -l basic_prompt $yellow(whoami)$normal" at "$green(hostname -s)$normal" in "$blue$path" "
# Prompt
set -l prompt
set -l UID (id -u $USER)
if [ "$UID" = "0" ]
set prompt "$red# "
else
set prompt "$normal% "
end
# Git stuff
set -l git_info
if [ (command git rev-parse --is-inside-work-tree ^/dev/null) ]
# Get the current branch name/commit
set -l git_branch_name (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
if [ -z $git_branch_name ]
set git_branch_name (command git show-ref --head -s --abbrev | head -n1 2> /dev/null)
end
# Unconditional git component
set git_info "$normal""on $white$git_branch_name"
if [ (command git status -s --ignore-submodules=dirty | wc -l) -gt 0 ]
set git_info "$git_info$yellow*"
end
set git_info "$git_info "
end
# Job count
set -l job_info
set -l job_count (jobs -c | wc -l | awk '{ print $1; }')
if [ $job_count -gt 0 ]
if [ $job_count -eq 1 ]
set job_info "$magenta""($job_count job)"
else
set job_info "$magenta""($job_count jobs)"
end
end
# Last command
set -l status_info ""
if [ $last_status -ne 0 ]
set status_info "$red""command failed with status: $last_status"
end
# WTB: time spend on last command (if ≥ 1s)
##################################################
# Output
if [ -n $status_info ]
echo -s $status_info
end
_rprint "$basic_prompt$git_info" $job_info
echo -n -s $prompt
end
## ocean
A fish theme with ocean in mind.
![Preview](https://cloud.githubusercontent.com/assets/129920/3533761/4702cc78-07d9-11e4-826f-e9f797e4bfa8.png)
Unicode-compatible fonts and terminals is required.
I would recommend iTerm2 + Solarized Dark for Mac users.
This theme is based loosely on [agnoster](https://gist.github.com/agnoster/3712874)
#### Characteristics
* Show a radioactive symbol (☢) when gain the root privileges (It's dangerous!)
* Current python virtualenv (if applicable)
* The anchor (⚓) turns red if the previous command failed
* Full path of current working directory
* Show the Git branch and dirty state (if applicable)
* Show **User@Hostname** if user is not the default user. Set the following two lines in your config.fish to turn on this feature:
```fish
set -g theme display_user yes
set -g default_user your_default_username
```
#### Troubleshooting in iTerm
If you see a colored anchor icon instead of the white one, this is because your system font is lacking the anchor icon, and iTerm defaults to the Apple Emoji Font. To get the right icon, either add it to your current font, or chose a powerline font that has it (like Meslo for Powerline, available in https://github.com/powerline/fonts), and select it for your Non-ASCII font.
# name: ocean
# A fish theme with ocean in mind.
## Set this options in your config.fish (if you want to)
# set -g theme_display_user yes
# set -g default_user default_username
set __oceanfish_glyph_anchor \u2693
set __oceanfish_glyph_flag \u2691
set __oceanfish_glyph_radioactive \u2622
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 last_status $status
set -l magenta (set_color magenta)
set -l red (set_color red)
set -l cyan (set_color cyan)
set -l white (set_color white)
set -l black (set_color black)
set -l bg_blue (set_color -b blue)
set -l bg_cyan (set_color -b cyan)
set -l bg_white (set_color -b white)
set -l bg_red (set_color -b red)
set -l bg_yellow (set_color -b yellow)
set -l normal (set_color normal)
set -l cwd $white(prompt_pwd)
set -l uid (id -u $USER)
# Show a yellow radioactive symbol for root privileges
if [ $uid -eq 0 ]
echo -n -s $bg_yellow $black " $__oceanfish_glyph_radioactive " $normal
end
# Display virtualenv name if in a virtualenv
if set -q VIRTUAL_ENV
echo -n -s $bg_cyan $black " " (basename "$VIRTUAL_ENV") " " $normal
end
# Show a nice anchor (turns red if previous command failed)
if test $last_status -ne 0
echo -n -s $bg_red $white " $__oceanfish_glyph_anchor " $normal
else
echo -n -s $bg_blue $white " $__oceanfish_glyph_anchor " $normal
end
if [ "$theme_display_user" = "yes" ]
if [ "$USER" != "$default_user" -o -n "$SSH_CLIENT" ]
echo -n -s $bg_white $cyan " " (whoami) "@" (hostname -s) " " $normal
end
end
# Display current path
echo -n -s $bg_cyan " $cwd " $normal
# Show git branch and dirty state
if [ (_git_branch_name) ]
set -l git_branch (_git_branch_name)
if [ (_is_git_dirty) ]
echo -n -s $bg_white $magenta " $git_branch " $red "$__oceanfish_glyph_flag " $normal
else
echo -n -s $bg_white $magenta " $git_branch " $normal
end
end
# Terminate with a space
echo -n -s ' ' $normal
end
## perryh
This is similar to godfat's gitstatus theme, but mainly includes red, white, cyan, and yellow.
![perryh](http://perryhuang.com/stuff/perryh_fish.png)
# name: perry
# Works best in a black or dark terminal background.
# https://github.com/perryh/oh-my-fish
# Mostly copied from: https://github.com/godfat/fish_prompt-gitstatus
function _git_branch_name
echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
end
function _git_status_symbol
set -l git_status (git status --porcelain ^/dev/null)
if test -n "$git_status"
# Is there anyway to preserve newlines so we can reuse $git_status?
if git status --porcelain ^/dev/null | grep '^.[^ ]' >/dev/null
echo '*' # dirty
else
echo '#' # all staged
end
else
echo '' # clean
end
end
function _remote_hostname
set -l red (set_color -o red)
set -l white (set_color -o white)
echo $white(whoami)$red@$white(hostname)
end
function fish_prompt
set -l red (set_color -o red)
set -l cyan (set_color -o cyan)
set -l yellow (set_color -o yellow)
set -l cwd (set_color $fish_color_cwd)(prompt_pwd)
set -l git_status (_git_status_symbol)(_git_branch_name)
if test -n "$git_status"
set git_status " $git_status"
end
echo -n (_remote_hostname)$red':'$cyan$cwd$yellow$git_status$red'➜ '
end
## robbyrussell
The default theme – cloned from oh-my-zsh.
![robbyrussell theme](https://bachue.github.io/oh-my-fish/images/robbyrussell-screenshot.png)
#### Characteristics
* Displays git information in the command prompt when available.
* If the last command was failed, the indicator would be red, otherwise it's green
# name: RobbyRussel
#
# You can override some default options in your config.fish:
# set -g theme_display_git_untracked no
function _git_branch_name
echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
end
function _is_git_dirty
set -l show_untracked (git config --bool bash.showUntrackedFiles)
set untracked ''
if [ "$theme_display_git_untracked" = 'no' -o "$show_untracked" = 'false' ]
set untracked '--untracked-files=no'
end
echo (command git status -s --ignore-submodules=dirty $untracked ^/dev/null)
end
function fish_prompt
set -l last_status $status
set -l cyan (set_color -o cyan)
set -l yellow (set_color -o yellow)
set -l red (set_color -o red)
set -l blue (set_color -o blue)
set -l green (set_color -o green)
set -l normal (set_color normal)
if test $last_status = 0
set arrow "$green➜ "
else
set arrow "$red➜ "
end
set -l cwd $cyan(basename (prompt_pwd))
if [ (_git_branch_name) ]
set -l git_branch $red(_git_branch_name)
set git_info "$blue git:($git_branch$blue)"
if [ (_is_git_dirty) ]
set -l dirty "$yellow ✗"
set git_info "$git_info$dirty"
end
end
echo -n -s $arrow ' ' $cwd $git_info $normal ' '
end
## Scorphish
Compact. Sufficient.
![scorphish](https://cloud.githubusercontent.com/assets/2112697/7443483/01d3dd56-f124-11e4-91c3-72a93fbc0dda.png)
#### Left prompt
Abbreviated path, ruby version, virtualenv and git info
#### Right prompt
Last command's exit code and current time
#### Acknowledgments
This theme is based on Zish and Coffeandcode themes, many thanks to their authors!
Enjoy!
function fish_greeting -d "what's up, fish?"
set_color $fish_color_autosuggestion[1]
uname -npsr
uptime
set_color normal
end
# name: scorphish
function _prompt_rubies -a sep_color -a ruby_color -d 'Display current Ruby (rvm/rbenv)'
[ "$theme_display_ruby" = 'no' ]; and return
set -l ruby_version
if type rvm-prompt >/dev/null 2>&1
set ruby_version (rvm-prompt i v g)
else if type rbenv >/dev/null 2>&1
set ruby_version (rbenv version-name)
# Don't show global ruby version...
[ "$ruby_version" = (rbenv global) ]; and return
end
[ -z "$ruby_version" ]; and return
echo -n -s $sep_color '|' $ruby_color $ruby_version
end
function _prompt_virtualfish -a sep_color -a venv_color -d "Display activated virtual environment (only for virtualfish, virtualenv's activate.fish changes prompt by itself)"
[ "$theme_display_virtualenv" = 'no' -o -z "$VIRTUAL_ENV" ]; and return
echo -n -s $sep_color '|' $venv_color (basename "$VIRTUAL_ENV")
end
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 _git_ahead_count -a remote -a branch_name
echo (command git log $remote/$branch_name..HEAD ^/dev/null | \
grep '^commit' | wc -l | tr -d ' ')
end
function _git_dirty_remotes -a remote_color -a ahead_color
set current_branch (command git rev-parse --abbrev-ref HEAD ^/dev/null)
set current_ref (command git rev-parse HEAD ^/dev/null)
for remote in (git remote)
set -l git_ahead_count (_git_ahead_count $remote $current_branch)
set remote_branch "refs/remotes/$remote/$current_branch"
set remote_ref (git for-each-ref --format='%(objectname)' $remote_branch)
if test "$remote_ref" != ''
if test "$remote_ref" != $current_ref
echo -n "$remote_color!"
if [ $git_ahead_count != 0 ]
echo -n "$ahead_color+$git_ahead_count$normal"
end
end
end
end
end
function fish_prompt
set -l exit_code $status
set -l gray (set_color 666)
set -l cyan (set_color cyan)
set -l red (set_color red)
set -l normal (set_color normal)
set -l yellow (set_color ffcc00)
set -l orange (set_color ffb300)
set -l green (set_color green)
set -l pink (set_color ff99ff)
set -l dark_pink (set_color cc99ff)
set_color -o 666
printf '['
set_color -o blue
printf '%s' (prompt_pwd)
_prompt_rubies $gray $red
_prompt_virtualfish $gray $green
set_color -o 666
if set -q SCORPHISH_GIT_INFO_ON_FIRST_LINE
printf ']'
else
printf ']\n'
end
# Show git branch and dirty state
if [ (_git_branch_name) ]
set -l git_branch (_git_branch_name)
set dirty_remotes (_git_dirty_remotes $red $orange)
if [ (_is_git_dirty) ]
echo -n -s $gray '‹' $yellow $git_branch $red '*' $dirty_remotes $gray '›' $normal
else
echo -n -s $gray '‹' $yellow $git_branch $red $dirty_remotes $gray '›' $normal
end
end
if test $exit_code -ne 0
set arrow_colors 600 900 c00 f00
else
set arrow_colors 060 090 0c0 0f0
end
if set -q SCORPHISH_GIT_INFO_ON_FIRST_LINE
printf '\n'
else
printf ' '
end
for arrow_color in $arrow_colors
set_color $arrow_color
printf '»'
end
printf ' '
set_color normal
end
function fish_right_prompt
set -l exit_code $status
if test $exit_code -ne 0
set_color red
else
set_color green
end
printf '%d' $exit_code
set_color -o 666
echo '|'
set_color -o 777
printf '%s' (date +%H:%M:%S)
set_color normal
end
\ No newline at end of file
function fish_title
[ "$theme_display_virtualenv" = 'no' -o -z "$VIRTUAL_ENV" ]; and printf '%s %s' $_ (pwd); and return
printf '%s %s' (basename "$VIRTUAL_ENV") (pwd)
end
\ No newline at end of file
fish_prompt-simplevi
====================
The stock prompt with the vi indicator appended.
It is meant to be used with the `vi-mode` plugin.
Screenshots:
![normal mode](https://raw.github.com/syl20bnr/fish_prompt-simplevi/master/prompt_fish-simplevi-n.png)
![insert mode](https://raw.github.com/syl20bnr/fish_prompt-simplevi/master/prompt_fish-simplevi-i.png)
# name: simplevi
function fish_prompt -d "Write out the prompt"
printf '%s@%s%s%s%s [%s]> ' (whoami) (hostname|cut -d . -f 1) (set_color $fish_color_cwd) (prompt_pwd) (set_color normal) $vi_mode
end
# syl20bnr theme
A semi-compact oh-my-fish theme with [nice support for git](#git).
The theme has been tested on `Ubuntu 14.04 (Trusty)` and `Mac OS X 10.10 (Yosemite)`.
It is also compatible with [Cygwin with the appropriate packages](#cygwin-compatibility).
**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
- [Segments](#segments)
- [pwd: Compact current working directory](#pwd-compact-current-working-directory)
- [Examples](#examples)
- [git](#git)
- [Examples](#examples-1)
- [vi-mode](#vi-mode)
- [end](#end)
- [where](#where)
- [Functions](#functions)
- [Mac compatibility](#mac-compatibility)
- [Cygwin compatibility](#cygwin-compatibility)
## Segments
### pwd: Compact current working directory
The `pwd` segment format is `X:P(N)` where:
- `X` is either `home` or `/`
- `P` is the current working path base name (name of the current directory)
- `N` is the depth of the path starting from `X`
If the `pwd` is `home` or `/` then the prompt format is simplified to `home`
and `/` respectively without the current directory and depth.
#### Examples
In home directory:
![home](https://raw.githubusercontent.com/syl20bnr/oh-my-fish-theme-syl20bnr/master/screenshots/prompt_fish-syl20bnr-home2.png)
Inside a directory in home:
![inside_home](https://raw.githubusercontent.com/syl20bnr/oh-my-fish-theme-syl20bnr/master/screenshots/prompt_fish-syl20bnr-inside-home.png)
Outside the home directory:
![outside_home](https://raw.githubusercontent.com/syl20bnr/oh-my-fish-theme-syl20bnr/master/screenshots/prompt_fish-syl20bnr-outside-home.png)
### git
If the current directory is a [git][git] repository then the `pwd` segment is
replaced by the `git` segment (I should know where I am).
The `git` segment format is `X:YI@Z:P(N)` where:
- `X` is `git`
- `Y` is the current branch name
- `I` is some information about the current repository state
- `Z` is the name of the repository
- `P` is the current working path basename (name of the current directory)
If `P` = `Z` then `P(N)` is not displayed
- `N` is the depth of the path starting from base directory of the repository
The displayed information `I` is:
- Unpushed commits are indicated with an up arrow like this `[↑1]`
- Unmerged fetched commits are indicated with a down arrow like this `[↓1]`
**Note:** The dirtiness of the current branch is indicated by its color:
- red: it is dirty
- green: it is up to date
**Note:** The unmerged commits count appears only if the changes in the
upstream branch as been fetched.
#### Examples
Dirty (changes not committed):
![dirty](https://raw.githubusercontent.com/syl20bnr/oh-my-fish-theme-syl20bnr/master/screenshots/prompt_fish-syl20bnr-git-dirty2.png)
Unpushed commits:
![unpushed_commits](https://raw.githubusercontent.com/syl20bnr/oh-my-fish-theme-syl20bnr/master/screenshots/prompt_fish-syl20bnr-git-unpushed.png)
Unmerged commits:
![unmerged_commits](https://raw.githubusercontent.com/syl20bnr/oh-my-fish-theme-syl20bnr/master/screenshots/prompt_fish-syl20bnr-git-unmerged.png)
Both unpushed and unmerged commits:
![unmerged_commits](https://raw.githubusercontent.com/syl20bnr/oh-my-fish-theme-syl20bnr/master/screenshots/prompt_fish-syl20bnr-git-unpushed_unmerged.png)
In a sub-directory of the repository:
![repo_subdir](https://raw.githubusercontent.com/syl20bnr/oh-my-fish-theme-syl20bnr/master/screenshots/prompt_fish-syl20bnr-git-subdir2.png)
### vi-mode
This segment display the current `vi-mode` if the fish native vi mode or
the oh-my-fish vi-mode plugin is used.
See the `[n]` in the previous screenshots.
### end
The color of the end of the prompt depends on the `$status` value of the
last executed command. It is `green` or `red` depending on the success or
failure of the last command.
Since I often use [ranger][ranger] and its `shift+s` key binding to bring
a new child shell session, there is a discreet indicator when the parent
process of the current shell is a `ranger` process: the end of the prompt
is written twice (ie: `>>` instead of just `>`).
With this indicator I quickly see if I can `ctrl+d` to end the current shell
process and go back to the parent `ranger` process.
### where
The `where` segment format is `X@Y` where:
- `X` is the user name
- `Y` is the host name
This segment is displayed in the right prompt.
## Functions
Some functions come with the theme:
- `toggle_right_prompt` will... toggle the right prompt! (alias: `trp`)
## Mac compatibility
In order to make this theme work correctly with all the features make sure to
install the following packages via MacPorts or Homebrew:
-`pstree` (used in ranger detection)
## Cygwin compatibility
In order to make this theme work on [Cygwin][cygwin], make sure to install the following
packages:
- `bc` for `math` fish function
- `psmisc` for `pstree` (used in ranger detection)
- `git` if you want to use the `git` segment.
[git]: http://git-scm.com/
[ranger]: http://ranger.nongnu.org/
[cygwin]: http://cygwin.com/
# name: syl20bnr
# ----------------------------------------------------------------------------
# Utils
# ----------------------------------------------------------------------------
set -g __syl20bnr_display_rprompt 1
function toggle_right_prompt -d "Toggle the right prompt of the syl20bnr theme"
if test $__syl20bnr_display_rprompt -eq 0
echo "enable right prompt"
set __syl20bnr_display_rprompt 1
else
echo "disable right prompt"
set __syl20bnr_display_rprompt 0
end
end
function __syl20bnr_git_branch_name -d "Return the current branch name"
echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
end
function __syl20bnr_git_repo_name -d "Return the current repository name"
echo (command basename (git rev-parse --show-toplevel ^/dev/null))
end
function __syl20bnr_git_repo_base -d "Return the current repository name"
echo (command git rev-parse --show-toplevel ^/dev/null)
end
function __syl20bnr_git_status -d "git status command"
git status -b -s --ignore-submodules=dirty
end
function __syl20bnr_unpushed_commit_count -d "Return the number of unpushed commits"
echo $argv[1] | grep -E -o "ahead\ [0-9]+" | awk '{print $2}'
end
function __syl20bnr_unmerged_commit_count -d "Return the number of unmerged commits"
echo $argv[1] | grep -E -o "behind\ [0-9]+" | awk '{print $2}'
end
# ----------------------------------------------------------------------------
# Aliases
# ----------------------------------------------------------------------------
alias trp toggle_right_prompt
# ----------------------------------------------------------------------------
# Prompts
# ----------------------------------------------------------------------------
function fish_prompt -d "Write out the left prompt of the syl20bnr theme"
set -l last_status $status
set -l basedir_name (basename (prompt_pwd))
# Init colors
set -l colcyan (set_color cyan)
set -l colbcyan (set_color -o cyan)
set -l colgreen (set_color green)
set -l colbgreen (set_color -o green)
set -l colnormal (set_color normal)
set -l colred (set_color red)
set -l colbred (set_color -o red)
set -l colwhite (set_color white)
set -l colbwhite (set_color -o white)
# Segments
# git
# If inside a git repo then the pwd segment is replaced by the git
# segment.
# The git segment format is X:YI@Z:P(N) where:
# X is git
# Y is the current branch
# I is the information about the current repo state
# Z is the name of the repo
# P is the current working path basename (name of the current directory)
# C is the depth of the path starting from base directory of the repo
# The displayed information is:
# Unpushed commits are indicated with up arrows
# The number of unpushed commits is indicated right after the up arrows
# Note:
# Dirtiness is indicated by the color of the branch name, red is dirty,
# green is up-to-date.
# If P = Z then P(C) is not displayed
set -l ps_git ""
set -l git_branch_name (__syl20bnr_git_branch_name)
if test -n "$git_branch_name"
set -l git_repo_name (__syl20bnr_git_repo_name)
set -l git_info ""
set -l git_status (__syl20bnr_git_status)
if echo $git_status | grep ahead > /dev/null
set git_info "["$colbgreen"↑"(__syl20bnr_unpushed_commit_count $git_status)$colnormal"]"
end
if echo $git_status | grep behind > /dev/null
set git_info "$git_info""["$colbred"↓"(__syl20bnr_unmerged_commit_count $git_status)$colnormal"]"
end
set -l colbranch $colbgreen
if echo $git_status | grep -E "\s\?\?\s|\sM\s|\sD\s" > /dev/null
set colbranch $colbred
end
set ps_git $colbwhite"git:"$colbcyan$git_branch_name$git_info$colnormal"@"$colbranch$git_repo_name
if test "$basedir_name" != "$git_repo_name"
set -l basedir_depth (echo (__syl20bnr_git_repo_base) | sed "s/\// /g" | wc -w)
set -l depth (echo (pwd) | sed "s/\// /g" | wc -w)
set depth (math $depth - $basedir_depth)
set ps_git $ps_git$colnormal":"$colbwhite$basedir_name$colnormal"("$depth")"
end
end
# pwd
# The pwd segment format is X:P(C) where:
# X is either home or /
# P is the current working path basename (name of the current directory)
# C is the depth of the path starting from X
# If the pwd is home or / then the prompt format is simplified to 'home' or
# '/' without the current directory and depth.
set -l ps_pwd ""
if test -z "$ps_git"
set -l depth (echo (pwd) | sed "s/\// /g" | wc -w)
set -l in_home (echo (pwd) | grep ~)
if test -n "$in_home"
set ps_pwd $colbwhite"home"
else
set ps_pwd $colbwhite"/"
end
if test (echo (pwd)) != ~ -a (echo (pwd)) != /
set ps_pwd $ps_pwd":"$colgreen$basedir_name
if test -n "$in_home"
set depth (math $depth - 2)
end
set ps_pwd $ps_pwd$colnormal"("$depth")"
end
end
# vi mode
# If vi_mode plugin or native vi mode is activated then print the vi mode
# in the prompt.
set -l ps_vi ""
if test -n "$vi_mode"
set ps_vi $colnormal"["$vi_mode$colnormal"]"
end
if test "$fish_key_bindings" = "fish_vi_key_bindings" -o "$fish_key_bindings" = "my_fish_key_bindings"
switch $fish_bind_mode
case default
set ps_vi $colnormal"("$colred"N"$colnormal")"
case insert
set ps_vi $colnormal"("$colgreen"I"$colnormal")"
case visual
set ps_vi $colnormal"("$colwhite"V"$colnormal")"
end
end
# end of prompt
# The color of the end of the prompt depends on the $status value of the
# last executed command. It is green or red depending on the last command
# success or failure respectively.
# Since I often use ranger and use its 'shift+s' key binding to bring a shell
# session, there is discreet indicator when the parent process of the current
# shell pid is a ranger process. In this case the end of the prompt is written
# twice.
# With this indicator I can quickly remember that I can "ctrl+d" to end the
# the current shell process and get back to the ranger process.
set -l ps_end ">"
# indicator for ranger parent process
set -l ranger ""
set -l os (uname)
if test "$os" = "Darwin"
if pstree -s ranger | grep (echo %self) | grep -v grep > /dev/null
set ranger 1
end
end
if test "$os" = "Linux"
if pstree -p -l | grep "fish("(echo %self)")" | grep 'ranger([0-9]*)' > /dev/null
set ranger 1
end
end
if test -n "$ranger"
set ps_end $ps_end$ps_end
end
# last status give the color of the right arrows at the end of the prompt
if test $last_status -ne 0
set ps_end $colnormal$colbred$ps_end
else
set ps_end $colnormal$colgreen$ps_end
end
# Left Prompt
echo -n -s $ps_git $ps_pwd $ps_vi $ps_git_dirty $ps_end ' '
end
function fish_right_prompt -d "Write out the right prompt of the syl20bnr theme"
set -l colnormal (set_color normal)
# Segments
# The where segment format is X@Y where:
# X is the username
# Y is the hostname
set -l ps_where $colnormal(whoami)@(hostname|cut -d . -f 1)
# Right Prompt
if test $__syl20bnr_display_rprompt -eq 1
echo -n -s $ps_where
end
end
## taktoa
A theme by taktoa
#### Characteristics
* Shows current git information
* Shows hostname if you are connected via ssh
* Show current terminal multiplexer status (screen/tmux pane name and number)
* Arrow is a lambda
![taktoa theme](http://taktoa.me/oh-my-fish/images/taktoa-screenshot.png)
# name: taktoa
# by taktoa (Remy Goldschmidt) <taktoa@gmail.com>
# License: public domain
function _git_branch_name
echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
end
function _git_status_symbol
set -l git_status (git status --porcelain ^/dev/null)
if test -n "$git_status"
if git status --porcelain ^/dev/null | grep '^.[^ ]' >/dev/null
echo '*' # dirty
else
echo '#' # all staged
end
else
echo '' # clean
end
end
function _remote_hostname
echo (whoami)
if test -n "$SSH_CONNECTION"
echo " (ssh)"
end
end
function _get_tmux_window
tmux lsw | grep active | sed 's/\*.*$//g;s/: / /1' | awk '{ print $2 "-" $1 }' -
end
function _get_screen_window
set initial (screen -Q windows; screen -Q echo "")
set middle (echo $initial | sed 's/ /\n/g' | grep '\*' | sed 's/\*\$ / /g')
echo $middle | awk '{ print $2 "-" $1 }' -
end
function _is_multiplexed
set multiplexer ""
if test -z $TMUX
else
set multiplexer "tmux"
end
if test -z $WINDOW
else
set multiplexer "screen"
end
echo $multiplexer
end
function fish_prompt
set -l cyan (set_color cyan)
set -l brown (set_color brown)
set -l normal (set_color normal)
set -l arrow "λ"
set -l cwd (set_color $fish_color_cwd)(prompt_pwd)
set -l git_status (_git_status_symbol)(_git_branch_name)
if test -n "$git_status"
set git_status " $git_status"
end
set multiplexer (_is_multiplexed)
switch $multiplexer
case screen
set pane (_get_screen_window)
case tmux
set pane (_get_tmux_window)
end
if test -z $pane
set window ""
else
set window " ($pane)"
end
echo -n -s (_remote_hostname) ' ' $cwd $brown $window $cyan $git_status $normal ' ' $arrow ' '
end
\ No newline at end of file
# Toaster
A fish (shell) theme with a poptart cat and a rainbow that signifies git status.
![Toaster in action](https://github.com/steeeve/toaster/raw/master/screenshot.png)
set __toaster_color_orange FD971F
set __toaster_color_blue 6EC9DD
set __toaster_color_green A6E22E
set __toaster_color_yellow E6DB7E
set __toaster_color_pink F92672
set __toaster_color_grey 554F48
set __toaster_color_white F1F1F1
set __toaster_color_purple 9458FF
set __toaster_color_lilac AE81FF
function __toaster_color_echo
set_color $argv[1]
if test (count $argv) -eq 2
echo -n $argv[2]
end
end
function __toaster_current_folder
if test $PWD = '/'
echo -n '/'
else
echo -n $PWD | grep -o -E '[^\/]+$'
end
end
function __toaster_git_status_codes
echo (git status --porcelain ^/dev/null | sed -E 's/(^.{3}).*/\1/' | tr -d ' \n')
end
function __toaster_git_branch_name
echo (git rev-parse --abbrev-ref HEAD ^/dev/null)
end
function __toaster_rainbow
if echo $argv[1] | grep -q -e $argv[3]
__toaster_color_echo $argv[2] "彡ミ"
end
end
function __toaster_git_status_icons
set -l git_status (__toaster_git_status_codes)
__toaster_rainbow $git_status $__toaster_color_pink 'D'
__toaster_rainbow $git_status $__toaster_color_orange 'R'
__toaster_rainbow $git_status $__toaster_color_white 'C'
__toaster_rainbow $git_status $__toaster_color_green 'A'
__toaster_rainbow $git_status $__toaster_color_blue 'U'
__toaster_rainbow $git_status $__toaster_color_lilac 'M'
__toaster_rainbow $git_status $__toaster_color_grey '?'
end
function __toaster_git_status
# In git
if test -n (__toaster_git_branch_name)
__toaster_color_echo $__toaster_color_blue " git"
__toaster_color_echo $__toaster_color_white ":"(__toaster_git_branch_name)
if test -n (__toaster_git_status_codes)
__toaster_color_echo $__toaster_color_pink ' ●'
__toaster_color_echo $__toaster_color_white ' [^._.^]ノ'
__toaster_git_status_icons
else
__toaster_color_echo $__toaster_color_green ' ○'
end
end
end
function fish_prompt
__toaster_color_echo $__toaster_color_blue "# "
__toaster_color_echo $__toaster_color_purple (__toaster_current_folder)
__toaster_git_status
echo
__toaster_color_echo $__toaster_color_pink "\$ "
end
A simple, but informative, prompt
![example](https://raw.githubusercontent.com/phaedryx/trout/master/prompt.png)
# name: trout
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 _file_count
ls -1 | wc -l | sed 's/\ //g'
end
function fish_prompt
set -l last_status $status
set -l yellow (set_color yellow)
set -l red (set_color red)
set -l green (set_color green)
set -l magenta (set_color magenta)
set -l normal (set_color normal)
if [ (rbenv version-name) ]
set ruby_version (rbenv version-name)
set ruby_info "$red($ruby_version)$normal"
end
if [ (_git_branch_name) ]
set -l git_branch $magenta(_git_branch_name)
set git_info "$git_branch"
if [ (_is_git_dirty) ]
set git_info "$git_info$yellow*"
end
set git_info "$magenta($git_info$magenta)$normal"
end
if test $last_status = 0
set prompt " $green☆$normal "
else
set prompt " $red☆$normal "
end
echo -n -s $ruby_info $git_info $prompt
end
function fish_right_prompt
set -l blue (set_color blue)
set -l normal (set_color normal)
set -l path (pwd)
set -l count (_file_count)
set -l directory_info "($path ($count))"
set -l time (date '+%I:%M')
set -l time_info "$blue($time)$normal"
echo -n -s $directory_info $time_info
end
## uggedal
Minimal theme.
![uggedal theme](https://f.cloud.github.com/assets/71/485623/c84ea45a-b8f7-11e2-8f7c-35a836aa7dbe.png)
#### Characteristics
* Only displays the `$CWD`.
* Displays hostname if you're connected through `ssh(1)`.
* Right prompt displays the last command's exit code if it was non-zero.
# name: Uggedal
function fish_prompt
if test -n "$SSH_CONNECTION"
printf '%s ' $HOSTNAME
end
printf '%s ' (prompt_pwd)
end
function fish_right_prompt
set -l last_status $status
if test $last_status -ne 0
set_color red
printf '%d' $last_status
set_color normal
end
end
## Will
Minimalist theme.
![Screenshot](https://cloud.githubusercontent.com/assets/143746/6462675/60d171fe-c1ab-11e4-9434-8718a2139c79.png)
#### Characteristics
* The current working directory is displayed on the right-side
* Hostnames are displayed if and only if we're on an SSH connection
* Uses logical entailment as the prompt character
function fish_prompt
if test -n "$SSH_CONNECTION"
printf '%s ' $HOSTNAME
end
set_color red
printf "⊨"
set_color normal
printf " "
end
function fish_right_prompt
set_color red
printf '%s ' (prompt_pwd)
set_color normal
end
## yimmy theme
A simple two-line theme best displayed on a terminal configured with Solarized
Dark colors.
user@host ~/c/w/dir (branch *)
>
![Screenshot](https://cloud.githubusercontent.com/assets/2502736/3245408/32c42cde-f172-11e3-8ba3-912191222a11.png)
Characteristics:
- Standard fish prompt characters: > for user, # for root
- Uses the fish `prompt_pwd`, so paths will be abbreviated
- Uses built-in `__fish_git_prompt` functionality
- Indicates Git work-in-progress (gwip/gunwip) if detected
- Prompt character is colored red if previous command had a non-zero exit
status
- Includes completmentary `LS_COLORS`
set -x LS_COLORS 'no=00;38;5;244:rs=0:di=00;38;5;33:ln=01;38;5;33:mh=00:pi=48;5;230;38;5;136;01:so=48;5;230;38;5;136;01:do=48;5;230;38;5;136;01:bd=48;5;230;38;5;244;01:cd=48;5;230;38;5;244;01:or=48;5;235;38;5;160:su=48;5;160;38;5;230:sg=48;5;136;38;5;230:ca=30;41:tw=48;5;64;38;5;230:ow=48;5;235;38;5;33:st=48;5;33;38;5;230:ex=01;38;5;64:*.tar=00;38;5;61:*.tgz=01;38;5;61:*.arj=01;38;5;61:*.taz=01;38;5;61:*.lzh=01;38;5;61:*.lzma=01;38;5;61:*.tlz=01;38;5;61:*.txz=01;38;5;61:*.zip=01;38;5;61:*.z=01;38;5;61:*.Z=01;38;5;61:*.dz=01;38;5;61:*.gz=01;38;5;61:*.lz=01;38;5;61:*.xz=01;38;5;61:*.bz2=01;38;5;61:*.bz=01;38;5;61:*.tbz=01;38;5;61:*.tbz2=01;38;5;61:*.tz=01;38;5;61:*.deb=01;38;5;61:*.rpm=01;38;5;61:*.jar=01;38;5;61:*.rar=01;38;5;61:*.ace=01;38;5;61:*.zoo=01;38;5;61:*.cpio=01;38;5;61:*.7z=01;38;5;61:*.rz=01;38;5;61:*.apk=01;38;5;61:*.jpg=00;38;5;136:*.JPG=00;38;5;136:*.jpeg=00;38;5;136:*.gif=00;38;5;136:*.bmp=00;38;5;136:*.pbm=00;38;5;136:*.pgm=00;38;5;136:*.ppm=00;38;5;136:*.tga=00;38;5;136:*.xbm=00;38;5;136:*.xpm=00;38;5;136:*.tif=00;38;5;136:*.tiff=00;38;5;136:*.png=00;38;5;136:*.svg=00;38;5;136:*.svgz=00;38;5;136:*.mng=00;38;5;136:*.pcx=00;38;5;136:*.dl=00;38;5;136:*.xcf=00;38;5;136:*.xwd=00;38;5;136:*.yuv=00;38;5;136:*.cgm=00;38;5;136:*.emf=00;38;5;136:*.eps=00;38;5;136:*.pdf=01;38;5;245:*.tex=01;38;5;245:*.rdf=01;38;5;245:*.owl=01;38;5;245:*.n3=01;38;5;245:*.tt=01;38;5;245:*.nt=01;38;5;245:*.log=00;38;5;240:*.bak=00;38;5;240:*.aux=00;38;5;240:*.bbl=00;38;5;240:*.blg=00;38;5;240:*.aac=00;38;5;166:*.au=00;38;5;166:*.flac=00;38;5;166:*.mid=00;38;5;166:*.midi=00;38;5;166:*.mka=00;38;5;166:*.mp3=00;38;5;166:*.mpc=00;38;5;166:*.ogg=00;38;5;166:*.ra=00;38;5;166:*.wav=00;38;5;166:*.axa=00;38;5;166:*.oga=00;38;5;166:*.spx=00;38;5;166:*.xspf=00;38;5;166:*.mov=01;38;5;166:*.mpg=01;38;5;166:*.mpeg=01;38;5;166:*.m2v=01;38;5;166:*.mkv=01;38;5;166:*.ogm=01;38;5;166:*.mp4=01;38;5;166:*.m4v=01;38;5;166:*.mp4v=01;38;5;166:*.vob=01;38;5;166:*.qt=01;38;5;166:*.nuv=01;38;5;166:*.wmv=01;38;5;166:*.asf=01;38;5;166:*.rm=01;38;5;166:*.rmvb=01;38;5;166:*.flc=01;38;5;166:*.avi=01;38;5;166:*.fli=01;38;5;166:*.flv=01;38;5;166:*.gl=01;38;5;166:*.axv=01;38;5;166:*.anx=01;38;5;166:*.ogv=01;38;5;166:*.ogx=01;38;5;166:'
set -e LSCOLORS
function fish_prompt
# Cache exit status
set -l last_status $status
# Just calculate these once, to save a few cycles when displaying the prompt
if not set -q __fish_prompt_hostname
set -g __fish_prompt_hostname (hostname|cut -d . -f 1)
end
if not set -q __fish_prompt_char
switch (id -u)
case 0
set -g __fish_prompt_char '#'
case '*'
set -g __fish_prompt_char '>'
end
end
# Setup colors
set -l normal (set_color normal)
set -l red (set_color red)
set -l cyan (set_color cyan)
set -l white (set_color white)
set -l gray (set_color -o cyan)
set -l brwhite (set_color -o white)
# Configure __fish_git_prompt
set -g __fish_git_prompt_showdirtystate true
set -g __fish_git_prompt_showuntrackedfiles true
set -g __fish_git_prompt_showstashstate true
set -g __fish_git_prompt_color green
set -g __fish_git_prompt_color_flags red
# Color prompt char red for non-zero exit status
set -l pcolor $gray
if test $last_status -ne 0
set pcolor $red
end
# Line 1
echo -n $red'┌'$cyan$USER$white'@'$cyan$__fish_prompt_hostname $gray(prompt_pwd)$normal
__fish_git_prompt
# Check for gwip; does last commit log contain --wip--?
if begin; git log -n 1 ^/dev/null | grep -qc "\-\-wip\-\-"; end
echo -n $brwhite' WIP!'$normal
end
echo
# Line 2
echo -n $red'└'$pcolor$__fish_prompt_char $normal
end
## Zish
Zhishen Wen's simple fun theme =)
![zish](https://raw.githubusercontent.com/bpinto/oh-my-fish/master/themes/zish/zish_preview.png)
#### Left prompt
User, host, abbreviated path, and git branch info
####Right prompt
Time and exit code
Enjoy!
# name: Zish
function _is_git_dirty
echo (command git status -s --ignore-submodules=dirty ^/dev/null)
end
function fish_prompt
set_color -o red
printf '┌─<'
set_color -o blue
printf '%s ' (whoami)
set_color $fish_color_autosuggestion[1]
printf '@ '
set_color cyan
printf '%s ' (hostname|cut -d . -f 1)
set_color $fish_color_autosuggestion[1]
printf 'in '
set_color -o green
printf '%s' (prompt_pwd)
set_color -o red
printf '>'
echo
set_color -o red
printf '└─<'
set_color yellow
printf '%s' (__fish_git_prompt)
if [ (_is_git_dirty) ]
set_color blue
printf '* '
end
set_color -o red
printf '>──'
set_color yellow
printf '» '
set_color normal
end
\ No newline at end of file
function fish_right_prompt
set -l exit_code $status
if test $exit_code -ne 0
set_color red
else
set_color green
end
printf '%d' $exit_code
set_color yellow
printf ' < %s' (date +%H:%M:%S)
set_color normal
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment