From 5a38bf4294ba641102146cda6fe553ed463fd238 Mon Sep 17 00:00:00 2001 From: Scott Perry Date: Wed, 1 May 2013 00:51:32 -0700 Subject: [PATCH 1/3] Initial theme import --- themes/numist/fish_prompt.fish | 96 ++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 themes/numist/fish_prompt.fish diff --git a/themes/numist/fish_prompt.fish b/themes/numist/fish_prompt.fish new file mode 100644 index 0000000..05b49ba --- /dev/null +++ b/themes/numist/fish_prompt.fish @@ -0,0 +1,96 @@ +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 basic_prompt $yellow(whoami)$normal" at "$green(hostname -s)$normal" in "$blue(pwd)" " + + # Prompt + set -l prompt + if [ "$UID" = "0" ] + set prompt "$red# " + else + set prompt "$normal% " + end + + # Git stuff + set -l git_info + if [ (git rev-parse --is-inside-work-tree ^/dev/null) ] + # Get the current branch name/commit + set -l git_branch_name (git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||') + if [ -z $git_branch_name ] + set git_branch_name (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 [ (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 From b089ef626d6379ed41d29f37981ad065dd9eb6db Mon Sep 17 00:00:00 2001 From: Scott Perry Date: Wed, 1 May 2013 01:00:14 -0700 Subject: [PATCH 2/3] Sane initial value for status_info --- themes/numist/fish_prompt.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/numist/fish_prompt.fish b/themes/numist/fish_prompt.fish index 05b49ba..8d32a61 100644 --- a/themes/numist/fish_prompt.fish +++ b/themes/numist/fish_prompt.fish @@ -78,7 +78,7 @@ function fish_prompt end # Last command - set -l status_info + set -l status_info "" if [ $last_status -ne 0 ] set status_info "$red""command failed with status: $last_status" end From f19a08341a986b840d4be6eeb1fddaeb9223b5d0 Mon Sep 17 00:00:00 2001 From: Scott Perry Date: Wed, 1 May 2013 01:06:25 -0700 Subject: [PATCH 3/3] Home directory contraction in path --- themes/numist/fish_prompt.fish | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/themes/numist/fish_prompt.fish b/themes/numist/fish_prompt.fish index 8d32a61..789f85e 100644 --- a/themes/numist/fish_prompt.fish +++ b/themes/numist/fish_prompt.fish @@ -37,7 +37,8 @@ function fish_prompt end # Unconditional stuff - set -l basic_prompt $yellow(whoami)$normal" at "$green(hostname -s)$normal" in "$blue(pwd)" " + 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