From bcd732aacc6a1bad700c8ceca5974656cbfc3cf2 Mon Sep 17 00:00:00 2001
From: Yigit Sever
Date: Thu, 11 Nov 2021 18:36:14 +0300
Subject: fish: welcome!

---
 .config/fish/functions/fish_greeting.fish          |  3 +
 .config/fish/functions/fish_prompt.fish            | 22 +++++++
 .config/fish/functions/fish_right_prompt.fish      | 75 ++++++++++++++++++++++
 .config/fish/functions/fish_user_key_bindings.fish |  3 +
 .config/fish/functions/n.fish                      | 33 ++++++++++
 .config/fish/functions/sh.fish                     |  3 +
 .config/fish/functions/take.fish                   | 12 ++++
 .config/fish/functions/te.fish                     |  7 ++
 8 files changed, 158 insertions(+)
 create mode 100644 .config/fish/functions/fish_greeting.fish
 create mode 100644 .config/fish/functions/fish_prompt.fish
 create mode 100644 .config/fish/functions/fish_right_prompt.fish
 create mode 100644 .config/fish/functions/fish_user_key_bindings.fish
 create mode 100644 .config/fish/functions/n.fish
 create mode 100644 .config/fish/functions/sh.fish
 create mode 100644 .config/fish/functions/take.fish
 create mode 100644 .config/fish/functions/te.fish

(limited to '.config/fish/functions')

diff --git a/.config/fish/functions/fish_greeting.fish b/.config/fish/functions/fish_greeting.fish
new file mode 100644
index 0000000..ee7303d
--- /dev/null
+++ b/.config/fish/functions/fish_greeting.fish
@@ -0,0 +1,3 @@
+function fish_greeting
+    fortune -a | cowsay -f small | lolcat
+end
diff --git a/.config/fish/functions/fish_prompt.fish b/.config/fish/functions/fish_prompt.fish
new file mode 100644
index 0000000..24e6e71
--- /dev/null
+++ b/.config/fish/functions/fish_prompt.fish
@@ -0,0 +1,22 @@
+function fish_prompt
+    set -l __last_command_exit_status $status
+
+    set -l cyan (set_color -o cyan)
+    set -l red (set_color -o red)
+    set -l green (set_color -o green)
+    set -l normal (set_color normal)
+
+    set -l marker_color "$green"
+    if test $__last_command_exit_status != 0
+        set marker_color "$red"
+    end
+
+    set -l marker "$marker_color" "δ"
+    if fish_is_root_user
+        set marker "$marker_color# "
+    end
+
+    set -l cwd $cyan (string join / (string split -rn -m3 / (prompt_pwd) | tail -n3))
+
+    echo -n -s $marker ' '$cwd $normal ' '
+end
diff --git a/.config/fish/functions/fish_right_prompt.fish b/.config/fish/functions/fish_right_prompt.fish
new file mode 100644
index 0000000..0dbcc37
--- /dev/null
+++ b/.config/fish/functions/fish_right_prompt.fish
@@ -0,0 +1,75 @@
+function fish_right_prompt -d "Write out the right prompt"
+
+    if not set -q -g __fish_right_prompt_functions_defined
+        set -g __fish_right_prompt_functions_defined
+        function _git_branch_name
+            set -l branch (git symbolic-ref --quiet HEAD 2>/dev/null)
+            if set -q branch[1]
+                echo (string replace -r '^refs/heads/' '' $branch)
+            else
+                echo (git rev-parse --short HEAD 2>/dev/null)
+            end
+        end
+
+        function _is_git_dirty
+            not command git diff-index --cached --quiet HEAD -- &>/dev/null
+            or not command git diff --no-ext-diff --quiet --exit-code &>/dev/null
+        end
+
+        function _is_git_repo
+            type -q git
+            or return 1
+            git rev-parse --git-dir >/dev/null 2>&1
+        end
+
+        function _hg_branch_name
+            echo (hg branch 2>/dev/null)
+        end
+
+        function _is_hg_dirty
+            set -l stat (hg status -mard 2>/dev/null)
+            test -n "$stat"
+        end
+
+        function _is_hg_repo
+            fish_print_hg_root >/dev/null
+        end
+
+        function _repo_branch_name
+            _$argv[1]_branch_name
+        end
+
+        function _is_repo_dirty
+            _is_$argv[1]_dirty
+        end
+
+        function _repo_type
+            if _is_hg_repo
+                echo hg
+                return 0
+            else if _is_git_repo
+                echo git
+                return 0
+            end
+            return 1
+        end
+    end
+
+    set -l yellow (set_color -o yellow)
+    set -l red (set_color -o red)
+    set -l blue (set_color -o blue)
+
+    set -l repo_info
+    if set -l repo_type (_repo_type)
+        set -l repo_branch $red(_repo_branch_name $repo_type)
+        set repo_info "$blue $repo_type:($repo_branch$blue)"
+
+        if _is_repo_dirty $repo_type
+            set -l dirty "$yellow ✗"
+            set repo_info "$repo_info$dirty"
+        end
+    end
+
+    set hour $blue(date '+%R')
+    echo -n -s $repo_info ' ' $hour
+end
diff --git a/.config/fish/functions/fish_user_key_bindings.fish b/.config/fish/functions/fish_user_key_bindings.fish
new file mode 100644
index 0000000..ff0d9f3
--- /dev/null
+++ b/.config/fish/functions/fish_user_key_bindings.fish
@@ -0,0 +1,3 @@
+function fish_user_key_bindings
+	fzf_key_bindings
+end
diff --git a/.config/fish/functions/n.fish b/.config/fish/functions/n.fish
new file mode 100644
index 0000000..042011c
--- /dev/null
+++ b/.config/fish/functions/n.fish
@@ -0,0 +1,33 @@
+function n --wraps=nnn --description 'support nnn quit and change directory'
+    # Block nesting of nnn in subshells
+    if test -n "$NNNLVL"
+        if [ (expr $NNNLVL + 0) -ge 1 ]
+            echo "nnn is already running"
+            return
+        end
+    end
+
+    # The behaviour is set to cd on quit (nnn checks if NNN_TMPFILE is set)
+    # To cd on quit only on ^G, remove the "-x" as in:
+    #    set NNN_TMPFILE "$XDG_CONFIG_HOME/nnn/.lastd"
+    #    (or, to a custom path: set NNN_TMPFILE "/tmp/.lastd")
+    # or, export NNN_TMPFILE after nnn invocation
+    if test -n "$XDG_CONFIG_HOME"
+        set NNN_TMPFILE "$XDG_CONFIG_HOME/nnn/.lastd"
+    else
+        set NNN_TMPFILE "$HOME/.config/nnn/.lastd"
+    end
+
+    # Unmask ^Q (, ^V etc.) (if required, see `stty -a`) to Quit nnn
+    # stty start undef
+    # stty stop undef
+    # stty lwrap undef
+    # stty lnext undef
+
+    nnn -c $argv
+
+    if test -e $NNN_TMPFILE
+        source $NNN_TMPFILE
+        rm $NNN_TMPFILE
+    end
+end
diff --git a/.config/fish/functions/sh.fish b/.config/fish/functions/sh.fish
new file mode 100644
index 0000000..3b7ae9a
--- /dev/null
+++ b/.config/fish/functions/sh.fish
@@ -0,0 +1,3 @@
+function sh --wraps=ssh --description 'ssh with correct TERM'
+    TERM=xterm-256color ssh $argv
+end
diff --git a/.config/fish/functions/take.fish b/.config/fish/functions/take.fish
new file mode 100644
index 0000000..407cf36
--- /dev/null
+++ b/.config/fish/functions/take.fish
@@ -0,0 +1,12 @@
+function take --description 'Create a directory and cd to it'
+    command mkdir $argv
+    if test $status = 0
+        switch $argv[(count $argv)]
+            case '-*'
+
+            case '*'
+                cd $argv[(count $argv)]
+                return
+        end
+    end
+end
diff --git a/.config/fish/functions/te.fish b/.config/fish/functions/te.fish
new file mode 100644
index 0000000..b0adca6
--- /dev/null
+++ b/.config/fish/functions/te.fish
@@ -0,0 +1,7 @@
+function te --description "take a temporary directory"
+    if set -q argv[1]
+        cd (command mktemp -d /tmp/$argv[1].XXXX)
+    else
+        cd (command mktemp -d /tmp/.XXXX)
+    end
+end
-- 
cgit v1.2.3-70-g09d2