summaryrefslogtreecommitdiff
path: root/functions
diff options
context:
space:
mode:
Diffstat (limited to 'functions')
-rw-r--r--functions/fish_prompt.fish377
1 files changed, 203 insertions, 174 deletions
diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish
index 05ff668..d3fce84 100644
--- a/functions/fish_prompt.fish
+++ b/functions/fish_prompt.fish
@@ -5,25 +5,53 @@
# set -g theme_hostname always
# set -g default_user your_normal_user
+set -g cmd_notification_threshold 15000
+function __d12_prompt__check_duration
+ if test (xdotool getactivewindow) -ne "$WINDOWID"
+ if test "$CMD_DURATION"
+ if test "$CMD_DURATION" -ge $cmd_notification_threshold
+ __d12_prompt__notify_completion "$CMD_DURATION"
+ __d12_prompt__on_duration_exceeded "$CMD_DURATION"
+ end
+ end
+ end
+ # set CMD_DURATION 0
+end
+
+function __d12_prompt__on_duration_exceeded -a duration
+ set_color $fish_color_command
+ echo -esn ' ~> duration: '
+ set_color $fish_color_param
+ echo -es $duration ' ms'
+ set_color normal
+end
+
+function __d12_prompt__notify_completion -a duration
+
+ set -l last_cmd_name (history | head -n 1 | cut -d' ' -f 1)
+ if command -v notify-send >/dev/null
+ notify-send fish (string join '' $last_cmd_name ' finished in ' $duration ' ms.') -t 0 --icon /usr/share/pixmaps/kitty.png
+ printf "\a" >(tty)
+ end
+end
# Backward compatibility
#
# Note: Do not depend on these behavior. These can be removed in anytime by the
# author in the name of code readability.
if set -q theme_hide_hostname
- # Existing $theme_hostname will always override $theme_hide_hostname
- if not set -q theme_hostname
- if [ "theme_hide_hostname" = "yes" ]
- set -g theme_hostname never
- end
- if [ "theme_hide_hostname" = "no" ]
- set -g theme_hostname always
+ # Existing $theme_hostname will always override $theme_hide_hostname
+ if not set -q theme_hostname
+ if [ theme_hide_hostname = yes ]
+ set -g theme_hostname never
+ end
+ if [ theme_hide_hostname = no ]
+ set -g theme_hostname always
+ end
end
- end
end
-
#
# Segments functions
#
@@ -31,109 +59,106 @@ set -g current_bg NONE
set -g segment_separator \uE0B0
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
+ 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
+ if [ -n $current_bg ]
+ set_color -b normal
+ set_color $current_bg
+ echo -n "$segment_separator "
+ end
+ set -g current_bg NONE
end
-
#
# Components
#
function prompt_virtual_env -d "Display Python virtual environment"
- if test "$VIRTUAL_ENV"
- prompt_segment white black (basename $VIRTUAL_ENV)
- end
+ if test "$VIRTUAL_ENV"
+ prompt_segment white black (basename $VIRTUAL_ENV)
+ end
end
-
function prompt_user -d "Display current user if different from $default_user"
- set -l BG 444444
- set -l FG BCBCBC
+ set -l BG 444444
+ set -l FG BCBCBC
- if [ "$theme_display_user" = "yes" ]
- if [ "$USER" != "$default_user" -o -n "$SSH_CLIENT" ]
- set USER (whoami)
- get_hostname
- if [ $HOSTNAME_PROMPT ]
- set USER_PROMPT $USER@$HOSTNAME_PROMPT
- else
- set USER_PROMPT $USER
- end
- prompt_segment $BG $FG $USER_PROMPT
- end
- else
- get_hostname
- if [ $HOSTNAME_PROMPT ]
- prompt_segment $BG $FG $HOSTNAME_PROMPT
+ if [ "$theme_display_user" = yes ]
+ if [ "$USER" != "$default_user" -o -n "$SSH_CLIENT" ]
+ set USER (whoami)
+ get_hostname
+ if [ $HOSTNAME_PROMPT ]
+ set USER_PROMPT $USER@$HOSTNAME_PROMPT
+ else
+ set USER_PROMPT $USER
+ end
+ prompt_segment $BG $FG $USER_PROMPT
+ end
+ else
+ get_hostname
+ if [ $HOSTNAME_PROMPT ]
+ prompt_segment $BG $FG $HOSTNAME_PROMPT
+ end
end
- end
end
function prompt_cloud -d "Display a Cloud if AWS connection detected"
- set -g HOSTNAME_PROMPT ""
- if [ "$AWS_PROFILE" != "" ]
- prompt_segment 494949 DDDDDD "☸️ $AWS_PROFILE"
- else
- if [ "$AWS_DEFAULT_PROFILE" != "" ]
- prompt_segment 494949 BBBBBB "🌩 $AWS_DEFAULT_PROFILE"
- end
- end
+ set -g HOSTNAME_PROMPT ""
+ if [ "$AWS_PROFILE" != "" ]
+ prompt_segment 494949 DDDDDD "☸️ $AWS_PROFILE"
+ else
+ if [ "$AWS_DEFAULT_PROFILE" != "" ]
+ prompt_segment 494949 BBBBBB "🌩 $AWS_DEFAULT_PROFILE"
+ end
+ end
end
function get_hostname -d "Set current hostname to prompt variable $HOSTNAME_PROMPT if connected via SSH or is root"
- set -g HOSTNAME_PROMPT ""
- if [ "$theme_hostname" = "always" -o \( "$theme_hostname" != "never" -a \( -n "$SSH_CLIENT" -o "$USER" = "root" \) \) ]
- if type hostnamectl 2> /dev/null > /dev/null
- set -g HOSTNAME_PROMPT (hostnamectl hostname)
- else if type hostname 2< /dev/null > /dev/null
- set -g HOSTNAME_PROMPT (hostname)
- else
- set -g HOSTNAME_PROMPT (cat /etc/hostname)
- end
- end
+ set -g HOSTNAME_PROMPT ""
+ if [ "$theme_hostname" = always -o \( "$theme_hostname" != never -a \( -n "$SSH_CLIENT" -o "$USER" = root \) \) ]
+ if type hostnamectl 2>/dev/null >/dev/null
+ set -g HOSTNAME_PROMPT (hostnamectl hostname)
+ else if type hostname 2</dev/null >/dev/null
+ set -g HOSTNAME_PROMPT (hostname)
+ else
+ set -g HOSTNAME_PROMPT (cat /etc/hostname)
+ end
+ end
end
-
function prompt_dir -d "Display the current directory"
- prompt_segment 1C1C1C FFFFFF (prompt_pwd)
+ prompt_segment 1C1C1C FFFFFF (prompt_pwd)
end
function git_status_summary -d "Deal with git status --porcelain"
- awk '
+ awk '
BEGIN {
untracked=0;
unstaged=0;
@@ -172,136 +197,140 @@ function git_status_summary -d "Deal with git status --porcelain"
end
function prompt_git -d "Display the current git state"
- set -l ref
- if [ -e .git ]
- set ref (command git symbolic-ref HEAD 2> /dev/null)
- if [ $status -gt 0 ]
- set -l branch (command git show-ref --head -s --abbrev 2> /dev/null |head -n1 2> /dev/null)
- set ref "➦ $branch "
- end
- set branch_symbol \uE0A0
- set -l branch (echo $ref | sed "s-refs/heads/-$branch_symbol -")
+ set -l ref
+ if [ -e .git ]
+ set ref (command git symbolic-ref HEAD 2> /dev/null)
+ if [ $status -gt 0 ]
+ set -l branch (command git show-ref --head -s --abbrev 2> /dev/null |head -n1 2> /dev/null)
+ set ref "➦ $branch "
+ end
+ set branch_symbol \uE0A0
+ set -l branch (echo $ref | sed "s-refs/heads/-$branch_symbol -")
- set dirty ''
- set gstatus ( git status --porcelain -b 2> /dev/null | git_status_summary )
+ set dirty ''
+ set gstatus ( git status --porcelain -b 2> /dev/null | git_status_summary )
- # Check for commit ahead
- set ahead (echo $gstatus | cut -d ';' -f 1)
- # Check for commit behind
- set behind (echo $gstatus | cut -d ';' -f 2)
- # Check for modified files
- set unstdg (echo $gstatus | cut -d ';' -f 3)
- # Check for untracked files
- set untrkd (echo $gstatus | cut -d ';' -f 4)
- # Check for staged files
- set staged (echo $gstatus | cut -d ';' -f 5)
+ # Check for commit ahead
+ set ahead (echo $gstatus | cut -d ';' -f 1)
+ # Check for commit behind
+ set behind (echo $gstatus | cut -d ';' -f 2)
+ # Check for modified files
+ set unstdg (echo $gstatus | cut -d ';' -f 3)
+ # Check for untracked files
+ set untrkd (echo $gstatus | cut -d ';' -f 4)
+ # Check for staged files
+ set staged (echo $gstatus | cut -d ';' -f 5)
- if [ $ahead -gt 0 ]
- set dirty $dirty'↑:'$ahead' '
- end
- if [ $behind -gt 0 ]
- set dirty $dirty'↓:'$behind' '
- end
+ if [ $ahead -gt 0 ]
+ set dirty $dirty'↑:'$ahead' '
+ end
+ if [ $behind -gt 0 ]
+ set dirty $dirty'↓:'$behind' '
+ end
- if [ $staged -eq 0 -a $untrkd -eq 0 ]
- set BG green
- set PROMPT "$branch $dirty"
- else
- set BG yellow
+ if [ $staged -eq 0 -a $untrkd -eq 0 ]
+ set BG green
+ set PROMPT "$branch $dirty"
+ else
+ set BG yellow
- # Check if there's any commit in the repo
- set -l empty 0
- git rev-parse --quiet --verify HEAD > /dev/null 2>&1; or set empty 1
+ # Check if there's any commit in the repo
+ set -l empty 0
+ git rev-parse --quiet --verify HEAD >/dev/null 2>&1; or set empty 1
- set -l target
- if [ $empty = 1 ]
- # The repo is empty
- set dirty 'βˆ…'
- set target '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
+ set -l target
+ if [ $empty = 1 ]
+ # The repo is empty
+ set dirty 'βˆ…'
+ set target 4b825dc642cb6eb9a060e54bf8d69288fbee4904
- else
- # The repo is not emtpy
- set target 'HEAD'
+ else
+ # The repo is not emtpy
+ set target HEAD
- # Check for unstaged change only when the repo is not empty
- set -l unstaged 0
- git diff --no-ext-diff --ignore-submodules=dirty --quiet --exit-code; or set unstaged 1
- if [ $unstaged = 1 ]; set dirty $dirty'●'; end
- end
+ # Check for unstaged change only when the repo is not empty
+ set -l unstaged 0
+ git diff --no-ext-diff --ignore-submodules=dirty --quiet --exit-code; or set unstaged 1
+ if [ $unstaged = 1 ]
+ set dirty $dirty'●'
+ end
+ end
- # Check for staged change
- set -l staged 0
- git diff-index --cached --quiet --exit-code --ignore-submodules=dirty $target; or set staged 1
- if [ $staged = 1 ]; set dirty $dirty'✚'; end
+ # Check for staged change
+ set -l staged 0
+ git diff-index --cached --quiet --exit-code --ignore-submodules=dirty $target; or set staged 1
+ if [ $staged = 1 ]
+ set dirty $dirty'✚'
+ end
- # Check for dirty
- if [ "$dirty" = "" ]
- set PROMPT "$branch"
- else
- set PROMPT "$branch $dirty"
- end
+ # Check for dirty
+ if [ "$dirty" = "" ]
+ set PROMPT "$branch"
+ else
+ set PROMPT "$branch $dirty"
+ end
+ end
+ prompt_segment $BG black $PROMPT
end
- prompt_segment $BG black $PROMPT
- 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 "✘"
+ prompt_segment black red "✘"
end
# if superuser (uid == 0)
set -l uid (id -u $USER)
if [ $uid -eq 0 ]
- prompt_segment black yellow "⚑"
+ prompt_segment black yellow "⚑"
end
# Jobs display
if [ (jobs -l | wc -l) -gt 0 ]
- prompt_segment black cyan "βš™"
+ prompt_segment black cyan "βš™"
end
end
function available -a name -d "Check if a function or program is available."
- type "$name" 2> /dev/null >&2
+ type "$name" 2>/dev/null >&2
end
function prompt_battery
- set str (acpi | grep -oP 'Full|Charging|Discharging|\d+%|\d+:\d+' | tr --truncate-set1 '\n' ' ' | read charging percent time)
+ set str (acpi | grep -oP 'Full|Charging|Discharging|\d+%|\d+:\d+' | tr --truncate-set1 '\n' ' ' | read charging percent time)
- if [ $time = "" ]
- set time "===="
- end
+ if [ $time = "" ]
+ set time "===="
+ end
- if [ $charging = "Charging" ]
- set charging "blue"
- else if [ $charging = "Discharging" ]
- set charging "green"
- else
- set charging "cyan"
- end
+ if [ $charging = Charging ]
+ set charging blue
+ else if [ $charging = Discharging ]
+ set charging green
+ else
+ set charging cyan
+ end
- set percent $percent
+ set percent $percent
- prompt_segment $charging white "$time $percent"
+ prompt_segment $charging white "$time $percent"
end
function prompt_time
- prompt_segment white black (date "+%H:%M:%S")
+ prompt_segment white black (date "+%H:%M:%S")
end
#
# Prompt
#
function fish_prompt
- set -g RETVAL $status
- prompt_time
- prompt_virtual_env
- prompt_status
- prompt_user
- prompt_dir
- available git; and prompt_git
- prompt_cloud
- prompt_finish
+ set -g RETVAL $status
+ __d12_prompt__check_duration
+ prompt_time
+ prompt_virtual_env
+ prompt_status
+ prompt_user
+ prompt_dir
+ available git; and prompt_git
+ prompt_cloud
+ prompt_finish
end