Skip to content

Instantly share code, notes, and snippets.

@swichers
Last active August 29, 2015 14:18
Show Gist options
  • Save swichers/5e3c368b003f9af76734 to your computer and use it in GitHub Desktop.
Save swichers/5e3c368b003f9af76734 to your computer and use it in GitHub Desktop.
Standalone cmorrell.com fish theme

This is a standalone version of the cmorrell theme available from oh-my-fish.

https://github.com/bpinto/oh-my-fish/tree/master/themes/cmorrell.com

Installation

  1. Place these files in your .config/fish/functions folder.
  2. Edit your .config/fish/config.fish file to set the default user: set -g default_user YOUR_USERNAME
  3. Close and reopen your shell
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" != "steven.wichers" -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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment