about summary refs log tree commit diff
path: root/configs/.config/fish/prompt.fish
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-03-06T11·19+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-03-06T18·45+0000
commit2eb9259a1b11b133390bfc74c9de69cc31a21349 (patch)
treebb4254af96da4596839b1608034d7931eb410723 /configs/.config/fish/prompt.fish
parentfe61dee51170a4aa7cdd984e03e56d4dc45afbb9 (diff)
Manage fish with home-manager
I patched home-manager locally to support fzf keybindings for fish. I will PR
this into home-manager, but I haven't yet, which means that my home.nix file
depends on my local ~/home-manager.
Diffstat (limited to 'configs/.config/fish/prompt.fish')
-rw-r--r--configs/.config/fish/prompt.fish82
1 files changed, 82 insertions, 0 deletions
diff --git a/configs/.config/fish/prompt.fish b/configs/.config/fish/prompt.fish
new file mode 100644
index 000000000000..17d807da0f02
--- /dev/null
+++ b/configs/.config/fish/prompt.fish
@@ -0,0 +1,82 @@
+# When the Emacs SSH client, Tramp, connects to a remote host that uses Fish,
+# it's important to keep the shell prompt simple so that Tramp can parse it.
+if test "$TERM" = "dumb"
+    function fish_prompt
+        echo "\$ "
+    end
+    function fish_right_prompt; end
+    function fish_greeting; end
+    function fish_title; end
+else
+    function fish_prompt
+        # My custom prompt.
+        #
+        # Design objectives:
+        # - max-length <= 80 characters
+        # - minimal
+        # - no dependencies (well, you know what I mean)
+        #
+        # Components
+        # - ssh connection
+        # - user
+        # - host
+        # - git repo
+        # - git branch
+        # - lambda character as prompt
+
+        # Cache status before we overwrite it.
+        set -l last_status $status
+
+        # Colors
+        set -l color_inactive (set_color red --bold)
+        set -l color_active (set_color green --bold)
+        set -l color_normal (set_color normal)
+
+        # SSH information
+        if set -q SSH_CLIENT; or set -q SSH_TTY
+            echo -en "$color_active \bssh ✓ [$color_normal$USER@"(hostname)"$color_active]$color_normal"
+        else
+            echo -en "$color_inactive \bssh ✗ [$color_normal$USER@"(hostname)"$color_inactive]$color_normal"
+        end
+
+        # Separator
+        echo -n " "
+
+        # Git information
+        set -l git_repo (git rev-parse --show-toplevel 2>/dev/null)
+        set -l git_status $status
+        set -l dir_parent (basename (realpath ..))
+        set -l dir_current (basename (realpath .))
+        if test $git_status -eq 0
+            set -l git_repo_name (basename (git rev-parse --show-toplevel))
+            set -l git_branch (git branch 2>/dev/null | grep '^\*' | cut -d' ' -f2-)
+            echo -en "$color_active \bgit ✓ [$color_normal$git_branch$color_active|$color_normal$git_repo_name$color_active|$color_normal$dir_parent/$dir_current$color_active]$color_normal"
+        else
+            echo -en "$color_inactive \bgit ✗ [$color_normal$dir_parent/$dir_current$color_inactive]$color_normal"
+        end
+
+        # Newline
+        echo
+
+        # Handle root vs non-root
+        if [ "$USER" = "root" ]
+            set -g prompt_sigil "#"
+        else
+            set -g prompt_sigil "λ"
+        end
+
+        # TODO(wpcarro): For root directories like /tmp, there will not be a parent
+        # directory. Support these directories.
+        set -l time (date +"%T")
+        if test $last_status -eq 0
+            set -l color_prompt (set_color white --bold)
+            echo -n "$time$color_prompt $prompt_sigil$color_normal "
+        else
+            set -l color_prompt (set_color red --bold)
+            echo -n "$time$color_prompt $prompt_sigil$color_normal "
+        end
+    end
+    function fish_right_prompt; end
+    function fish_greeting; end
+    function fish_title; end
+end