diff --git a/etc/fish/config.fish b/etc/fish/config.fish new file mode 100644 index 0000000..909a70e --- /dev/null +++ b/etc/fish/config.fish @@ -0,0 +1 @@ +set -g fish_greeting diff --git a/etc/fish/functions/fish_prompt.fish b/etc/fish/functions/fish_prompt.fish new file mode 100644 index 0000000..e29bfc3 --- /dev/null +++ b/etc/fish/functions/fish_prompt.fish @@ -0,0 +1,33 @@ +function fish_prompt + set -l last_status "$status" + set -l tty (tty) + + # autostart sway on tty1 + if test "$tty" = "/dev/tty1" + command sway + end + + # show last exit code if != 0 + if test "$last_status" -gt 0 + set_color red + printf '%s ' "$last_status" + end + + # show hostname on ssh connection + if test -n "$SSH_CLIENT" + set_color brblack + set -l host (uname -n) + printf '[%s] ' $host + end + + # username + if test $USER = "root" + set_color -o brred + printf '\x24 ' + else + set_color -o brblue + printf '\x25 ' + end + + set_color normal +end diff --git a/etc/fish/functions/fish_right_prompt.fish b/etc/fish/functions/fish_right_prompt.fish new file mode 100644 index 0000000..2b24fe3 --- /dev/null +++ b/etc/fish/functions/fish_right_prompt.fish @@ -0,0 +1,36 @@ +function fish_command_timer_compute_cmd_duration_str + if [ $CMD_DURATION -lt 10000 ] + return + end + + set -l SEC 1000 + set -l MIN 60000 + set -l HOUR 3600000 + set -l DAY 86400000 + + set -l num_days (math -s0 "$CMD_DURATION / $DAY") + set -l num_hours (math -s0 "$CMD_DURATION % $DAY / $HOUR") + set -l num_mins (math -s0 "$CMD_DURATION % $HOUR / $MIN") + set -l num_secs (math -s0 "$CMD_DURATION % $MIN / $SEC") + set -l cmd_duration_str "" + if [ $num_days -gt 0 ] + set cmd_duration_str {$cmd_duration_str}{$num_days}"d " + end + if [ $num_hours -gt 0 ] + set cmd_duration_str {$cmd_duration_str}{$num_hours}"h " + end + if [ $num_mins -gt 0 ] + set cmd_duration_str {$cmd_duration_str}{$num_mins}"m " + end + set cmd_duration_str {$cmd_duration_str}{$num_secs}s + printf '%s ' $cmd_duration_str +end + +function fish_right_prompt + set_color brblack + fish_command_timer_compute_cmd_duration_str + + set_color green + printf '%s ' (prompt_pwd) + set_color normal +end