diff options
Diffstat (limited to '.config/fish/functions')
-rw-r--r-- | .config/fish/functions/fish_greeting.fish | 3 | ||||
-rw-r--r-- | .config/fish/functions/fish_prompt.fish | 22 | ||||
-rw-r--r-- | .config/fish/functions/fish_right_prompt.fish | 75 | ||||
-rw-r--r-- | .config/fish/functions/fish_user_key_bindings.fish | 3 | ||||
-rw-r--r-- | .config/fish/functions/n.fish | 33 | ||||
-rw-r--r-- | .config/fish/functions/sh.fish | 3 | ||||
-rw-r--r-- | .config/fish/functions/take.fish | 12 | ||||
-rw-r--r-- | .config/fish/functions/te.fish | 7 |
8 files changed, 158 insertions, 0 deletions
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 @@ | |||
1 | function fish_greeting | ||
2 | fortune -a | cowsay -f small | lolcat | ||
3 | 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 @@ | |||
1 | function fish_prompt | ||
2 | set -l __last_command_exit_status $status | ||
3 | |||
4 | set -l cyan (set_color -o cyan) | ||
5 | set -l red (set_color -o red) | ||
6 | set -l green (set_color -o green) | ||
7 | set -l normal (set_color normal) | ||
8 | |||
9 | set -l marker_color "$green" | ||
10 | if test $__last_command_exit_status != 0 | ||
11 | set marker_color "$red" | ||
12 | end | ||
13 | |||
14 | set -l marker "$marker_color" "δ" | ||
15 | if fish_is_root_user | ||
16 | set marker "$marker_color# " | ||
17 | end | ||
18 | |||
19 | set -l cwd $cyan (string join / (string split -rn -m3 / (prompt_pwd) | tail -n3)) | ||
20 | |||
21 | echo -n -s $marker ' '$cwd $normal ' ' | ||
22 | 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 @@ | |||
1 | function fish_right_prompt -d "Write out the right prompt" | ||
2 | |||
3 | if not set -q -g __fish_right_prompt_functions_defined | ||
4 | set -g __fish_right_prompt_functions_defined | ||
5 | function _git_branch_name | ||
6 | set -l branch (git symbolic-ref --quiet HEAD 2>/dev/null) | ||
7 | if set -q branch[1] | ||
8 | echo (string replace -r '^refs/heads/' '' $branch) | ||
9 | else | ||
10 | echo (git rev-parse --short HEAD 2>/dev/null) | ||
11 | end | ||
12 | end | ||
13 | |||
14 | function _is_git_dirty | ||
15 | not command git diff-index --cached --quiet HEAD -- &>/dev/null | ||
16 | or not command git diff --no-ext-diff --quiet --exit-code &>/dev/null | ||
17 | end | ||
18 | |||
19 | function _is_git_repo | ||
20 | type -q git | ||
21 | or return 1 | ||
22 | git rev-parse --git-dir >/dev/null 2>&1 | ||
23 | end | ||
24 | |||
25 | function _hg_branch_name | ||
26 | echo (hg branch 2>/dev/null) | ||
27 | end | ||
28 | |||
29 | function _is_hg_dirty | ||
30 | set -l stat (hg status -mard 2>/dev/null) | ||
31 | test -n "$stat" | ||
32 | end | ||
33 | |||
34 | function _is_hg_repo | ||
35 | fish_print_hg_root >/dev/null | ||
36 | end | ||
37 | |||
38 | function _repo_branch_name | ||
39 | _$argv[1]_branch_name | ||
40 | end | ||
41 | |||
42 | function _is_repo_dirty | ||
43 | _is_$argv[1]_dirty | ||
44 | end | ||
45 | |||
46 | function _repo_type | ||
47 | if _is_hg_repo | ||
48 | echo hg | ||
49 | return 0 | ||
50 | else if _is_git_repo | ||
51 | echo git | ||
52 | return 0 | ||
53 | end | ||
54 | return 1 | ||
55 | end | ||
56 | end | ||
57 | |||
58 | set -l yellow (set_color -o yellow) | ||
59 | set -l red (set_color -o red) | ||
60 | set -l blue (set_color -o blue) | ||
61 | |||
62 | set -l repo_info | ||
63 | if set -l repo_type (_repo_type) | ||
64 | set -l repo_branch $red(_repo_branch_name $repo_type) | ||
65 | set repo_info "$blue $repo_type:($repo_branch$blue)" | ||
66 | |||
67 | if _is_repo_dirty $repo_type | ||
68 | set -l dirty "$yellow ✗" | ||
69 | set repo_info "$repo_info$dirty" | ||
70 | end | ||
71 | end | ||
72 | |||
73 | set hour $blue(date '+%R') | ||
74 | echo -n -s $repo_info ' ' $hour | ||
75 | 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 @@ | |||
1 | function fish_user_key_bindings | ||
2 | fzf_key_bindings | ||
3 | 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 @@ | |||
1 | function n --wraps=nnn --description 'support nnn quit and change directory' | ||
2 | # Block nesting of nnn in subshells | ||
3 | if test -n "$NNNLVL" | ||
4 | if [ (expr $NNNLVL + 0) -ge 1 ] | ||
5 | echo "nnn is already running" | ||
6 | return | ||
7 | end | ||
8 | end | ||
9 | |||
10 | # The behaviour is set to cd on quit (nnn checks if NNN_TMPFILE is set) | ||
11 | # To cd on quit only on ^G, remove the "-x" as in: | ||
12 | # set NNN_TMPFILE "$XDG_CONFIG_HOME/nnn/.lastd" | ||
13 | # (or, to a custom path: set NNN_TMPFILE "/tmp/.lastd") | ||
14 | # or, export NNN_TMPFILE after nnn invocation | ||
15 | if test -n "$XDG_CONFIG_HOME" | ||
16 | set NNN_TMPFILE "$XDG_CONFIG_HOME/nnn/.lastd" | ||
17 | else | ||
18 | set NNN_TMPFILE "$HOME/.config/nnn/.lastd" | ||
19 | end | ||
20 | |||
21 | # Unmask ^Q (, ^V etc.) (if required, see `stty -a`) to Quit nnn | ||
22 | # stty start undef | ||
23 | # stty stop undef | ||
24 | # stty lwrap undef | ||
25 | # stty lnext undef | ||
26 | |||
27 | nnn -c $argv | ||
28 | |||
29 | if test -e $NNN_TMPFILE | ||
30 | source $NNN_TMPFILE | ||
31 | rm $NNN_TMPFILE | ||
32 | end | ||
33 | 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 @@ | |||
1 | function sh --wraps=ssh --description 'ssh with correct TERM' | ||
2 | TERM=xterm-256color ssh $argv | ||
3 | 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 @@ | |||
1 | function take --description 'Create a directory and cd to it' | ||
2 | command mkdir $argv | ||
3 | if test $status = 0 | ||
4 | switch $argv[(count $argv)] | ||
5 | case '-*' | ||
6 | |||
7 | case '*' | ||
8 | cd $argv[(count $argv)] | ||
9 | return | ||
10 | end | ||
11 | end | ||
12 | 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 @@ | |||
1 | function te --description "take a temporary directory" | ||
2 | if set -q argv[1] | ||
3 | cd (command mktemp -d /tmp/$argv[1].XXXX) | ||
4 | else | ||
5 | cd (command mktemp -d /tmp/.XXXX) | ||
6 | end | ||
7 | end | ||