From 331c9b0e69230dc919512db540643894da9c3985 Mon Sep 17 00:00:00 2001 From: Von Random Date: Sun, 5 Feb 2023 22:13:01 +0200 Subject: [PATCH] fish: some functions and aliases --- cli/.config/fish/config.fish | 51 +++++---------------- cli/.config/fish/functions/atmux.fish | 3 ++ cli/.config/fish/functions/diff.fish | 3 ++ cli/.config/fish/functions/fish_prompt.fish | 10 ++++ cli/.config/fish/functions/g.fish | 3 ++ cli/.config/fish/functions/gci.fish | 3 ++ cli/.config/fish/functions/grep.fish | 3 ++ cli/.config/fish/functions/greset.fish | 6 +++ cli/.config/fish/functions/groot.fish | 4 ++ cli/.config/fish/functions/gsi.fish | 3 ++ cli/.config/fish/functions/gsl.fish | 3 ++ cli/.config/fish/functions/gss.fish | 3 ++ cli/.config/fish/functions/gsw.fish | 3 ++ cli/.config/fish/functions/gup.fish | 3 ++ cli/.config/fish/functions/gwta.fish | 3 ++ cli/.config/fish/functions/gwtp.fish | 3 ++ cli/.config/fish/functions/ll.fish | 3 ++ cli/.config/fish/functions/ls.fish | 3 ++ cli/.config/fish/functions/prompt.add.fish | 10 ++++ cli/.config/fish/functions/prompt.git.fish | 20 ++++++++ cli/.config/fish/functions/rgrep.fish | 3 ++ cli/.config/fish/functions/tailf.fish | 3 ++ cli/.config/fish/functions/tmux.fish | 3 ++ cli/.config/fish/functions/vim.fish | 3 ++ 24 files changed, 115 insertions(+), 40 deletions(-) create mode 100644 cli/.config/fish/functions/atmux.fish create mode 100644 cli/.config/fish/functions/diff.fish create mode 100644 cli/.config/fish/functions/fish_prompt.fish create mode 100644 cli/.config/fish/functions/g.fish create mode 100644 cli/.config/fish/functions/gci.fish create mode 100644 cli/.config/fish/functions/grep.fish create mode 100644 cli/.config/fish/functions/greset.fish create mode 100644 cli/.config/fish/functions/groot.fish create mode 100644 cli/.config/fish/functions/gsi.fish create mode 100644 cli/.config/fish/functions/gsl.fish create mode 100644 cli/.config/fish/functions/gss.fish create mode 100644 cli/.config/fish/functions/gsw.fish create mode 100644 cli/.config/fish/functions/gup.fish create mode 100644 cli/.config/fish/functions/gwta.fish create mode 100644 cli/.config/fish/functions/gwtp.fish create mode 100644 cli/.config/fish/functions/ll.fish create mode 100644 cli/.config/fish/functions/ls.fish create mode 100644 cli/.config/fish/functions/prompt.add.fish create mode 100644 cli/.config/fish/functions/prompt.git.fish create mode 100644 cli/.config/fish/functions/rgrep.fish create mode 100644 cli/.config/fish/functions/tailf.fish create mode 100644 cli/.config/fish/functions/tmux.fish create mode 100644 cli/.config/fish/functions/vim.fish diff --git a/cli/.config/fish/config.fish b/cli/.config/fish/config.fish index 0169d01..ef2d1f1 100644 --- a/cli/.config/fish/config.fish +++ b/cli/.config/fish/config.fish @@ -1,49 +1,20 @@ if status is-interactive set prompt_sep_a \ue0b0 - set prompt_bang \n\U1f41f\ + set prompt_bang \n\ (set_color brblue)\u266a\ set git_sign \ue0a0 set color_fg brwhite set color_git_branch 3c3c3c set color_git yellow blue red purple - function prompt.add - set color $argv[1] - set text $argv[2] - if test -z "$prompt_string" - set prompt_string (set_color -b $color)(set_color $color_fg) $text - else - set -a prompt_string (set_color -b $color)(set_color $prev_color)$prompt_sep_a(set_color $color_fg) $text - end - set prev_color $color - end - function prompt.git - git rev-parse 2>/dev/null || return - git status --porcelain -bu | while read line - if string match -qr "^##" "$line" - set git_branch (string match -r "\ (.+)\.\.\." "$line")[2] - string match -qr "\[behind" $line && set git_branch "$git_branch?" - string match -qr "\[ahead" $line && set git_branch "$git_branch!" - prompt.add "$color_git_branch" "$git_sign $git_branch" - else - string match -qr "^.[MD]" "$line" && set git_count[1] (math $git_count[1] + 1) - string match -qr "^[MDARC]." "$line" && set git_count[2] (math $git_count[2] + 1) - string match -qr "^\?\?" "$line" && set git_count[3] (math $git_count[3] + 1) - string match -qr "^[ADU]{2}" "$line" && set git_count[4] (math $git_count[4] + 1) - end - end - test -n "$git_count[1]" && prompt.add "$color_git[1]" "~$git_count[1]" - test -n "$git_count[2]" && prompt.add "$color_git[2]" "+$git_count[2]" - test -n "$git_count[3]" && prompt.add "$color_git[3]" "!$git_count[3]" - test -n "$git_count[4]" && prompt.add "$color_git[4]" "*$git_count[4]" - end - function fish_prompt - set -g prompt_string - set -g prev_color - prompt.add blue (pwd) - prompt.git - prompt.add normal $prompt_bang - echo $prompt_string - set -e prompt_string + set -l grc_cmds \ + iptables ipneighbor ipaddr iproute ip nmap netstat \ + traceroute tcpdump ss ping \ + dockerversion dockersearch dockerpull dockerps dockernetwork \ + docker-machinels dockerinfo dockerimages \ + lspci lsof lsmod lsblk lsattr getfacl id whois vmstat ulimit \ + systemctl sysctl stat pv ps ping last gcc free findmnt fdisk env du \ + dig diff df blkid + for cmd in $grc_cmds + command -q $cmd && alias $cmd="command grc -es --colour=auto $cmd" end - # Commands to run in interactive sessions can go here end diff --git a/cli/.config/fish/functions/atmux.fish b/cli/.config/fish/functions/atmux.fish new file mode 100644 index 0000000..27ea6c3 --- /dev/null +++ b/cli/.config/fish/functions/atmux.fish @@ -0,0 +1,3 @@ +function atmux + tmux attach || tmux +end diff --git a/cli/.config/fish/functions/diff.fish b/cli/.config/fish/functions/diff.fish new file mode 100644 index 0000000..cb682dd --- /dev/null +++ b/cli/.config/fish/functions/diff.fish @@ -0,0 +1,3 @@ +function diff + command diff --color $argv +end diff --git a/cli/.config/fish/functions/fish_prompt.fish b/cli/.config/fish/functions/fish_prompt.fish new file mode 100644 index 0000000..990c9ab --- /dev/null +++ b/cli/.config/fish/functions/fish_prompt.fish @@ -0,0 +1,10 @@ +function fish_prompt + set -g prompt_string + set -g prev_color + prompt.add blue (pwd) + prompt.git + prompt.add normal $prompt_bang + + echo $prompt_string + set -e prompt_string +end diff --git a/cli/.config/fish/functions/g.fish b/cli/.config/fish/functions/g.fish new file mode 100644 index 0000000..8f9e124 --- /dev/null +++ b/cli/.config/fish/functions/g.fish @@ -0,0 +1,3 @@ +function g + command lazygit $argv +end diff --git a/cli/.config/fish/functions/gci.fish b/cli/.config/fish/functions/gci.fish new file mode 100644 index 0000000..ca0cb3e --- /dev/null +++ b/cli/.config/fish/functions/gci.fish @@ -0,0 +1,3 @@ +function gci + command git commit $argv +end diff --git a/cli/.config/fish/functions/grep.fish b/cli/.config/fish/functions/grep.fish new file mode 100644 index 0000000..b5e2fa3 --- /dev/null +++ b/cli/.config/fish/functions/grep.fish @@ -0,0 +1,3 @@ +function grep + command grep --color=auto $argv +end diff --git a/cli/.config/fish/functions/greset.fish b/cli/.config/fish/functions/greset.fish new file mode 100644 index 0000000..b2155af --- /dev/null +++ b/cli/.config/fish/functions/greset.fish @@ -0,0 +1,6 @@ +function greset + read -P "OK to reset and clean teh repo?"\n -ln1 resp + test "$resp" != y && return 0 + command git clean -fd + command git reset --hard +end diff --git a/cli/.config/fish/functions/groot.fish b/cli/.config/fish/functions/groot.fish new file mode 100644 index 0000000..39dff47 --- /dev/null +++ b/cli/.config/fish/functions/groot.fish @@ -0,0 +1,4 @@ +function groot + set -l root (command git rev-parse --show-toplevel) + test $status -eq 0 && cd $root +end diff --git a/cli/.config/fish/functions/gsi.fish b/cli/.config/fish/functions/gsi.fish new file mode 100644 index 0000000..dd40563 --- /dev/null +++ b/cli/.config/fish/functions/gsi.fish @@ -0,0 +1,3 @@ +function gsi + tig status +end diff --git a/cli/.config/fish/functions/gsl.fish b/cli/.config/fish/functions/gsl.fish new file mode 100644 index 0000000..12a353b --- /dev/null +++ b/cli/.config/fish/functions/gsl.fish @@ -0,0 +1,3 @@ +function gsl + command git stash list $argv +end diff --git a/cli/.config/fish/functions/gss.fish b/cli/.config/fish/functions/gss.fish new file mode 100644 index 0000000..d3aa60d --- /dev/null +++ b/cli/.config/fish/functions/gss.fish @@ -0,0 +1,3 @@ +function gss + command git status -sbu $argv +end diff --git a/cli/.config/fish/functions/gsw.fish b/cli/.config/fish/functions/gsw.fish new file mode 100644 index 0000000..ef8be05 --- /dev/null +++ b/cli/.config/fish/functions/gsw.fish @@ -0,0 +1,3 @@ +function gsw + command git switch $argv +end diff --git a/cli/.config/fish/functions/gup.fish b/cli/.config/fish/functions/gup.fish new file mode 100644 index 0000000..43522f2 --- /dev/null +++ b/cli/.config/fish/functions/gup.fish @@ -0,0 +1,3 @@ +function gup + command git pull $argv +end diff --git a/cli/.config/fish/functions/gwta.fish b/cli/.config/fish/functions/gwta.fish new file mode 100644 index 0000000..aad6902 --- /dev/null +++ b/cli/.config/fish/functions/gwta.fish @@ -0,0 +1,3 @@ +function gwta + command git worktree add $argv +end diff --git a/cli/.config/fish/functions/gwtp.fish b/cli/.config/fish/functions/gwtp.fish new file mode 100644 index 0000000..36eff0e --- /dev/null +++ b/cli/.config/fish/functions/gwtp.fish @@ -0,0 +1,3 @@ +function gwtp + command git worktree purge $argv +end diff --git a/cli/.config/fish/functions/ll.fish b/cli/.config/fish/functions/ll.fish new file mode 100644 index 0000000..b0225a9 --- /dev/null +++ b/cli/.config/fish/functions/ll.fish @@ -0,0 +1,3 @@ +function ll + ls -alg $argv +end diff --git a/cli/.config/fish/functions/ls.fish b/cli/.config/fish/functions/ls.fish new file mode 100644 index 0000000..6090522 --- /dev/null +++ b/cli/.config/fish/functions/ls.fish @@ -0,0 +1,3 @@ +function ls + command exa --group-directories-first $argv +end diff --git a/cli/.config/fish/functions/prompt.add.fish b/cli/.config/fish/functions/prompt.add.fish new file mode 100644 index 0000000..1b79daa --- /dev/null +++ b/cli/.config/fish/functions/prompt.add.fish @@ -0,0 +1,10 @@ +function prompt.add + set color $argv[1] + set text $argv[2] + if test -z "$prompt_string" + set prompt_string (set_color -b $color)(set_color $color_fg) $text + else + set -a prompt_string (set_color -b $color)(set_color $prev_color)$prompt_sep_a(set_color $color_fg) $text + end + set prev_color $color +end diff --git a/cli/.config/fish/functions/prompt.git.fish b/cli/.config/fish/functions/prompt.git.fish new file mode 100644 index 0000000..6f00bcc --- /dev/null +++ b/cli/.config/fish/functions/prompt.git.fish @@ -0,0 +1,20 @@ +function prompt.git + git rev-parse 2>/dev/null || return + git status --porcelain -bu | while read line + if string match -qr "^##" "$line" + set git_branch (string match -r "\ (.+)\.\.\." "$line")[2] + string match -qr '\[behind' $line && set git_branch "$git_branch?" + string match -qr '\[ahead' $line && set git_branch "$git_branch!" + prompt.add "$color_git_branch" "$git_sign $git_branch" + else + string match -qr "^.[MD]" "$line" && set git_count[1] (math $git_count[1] + 1) + string match -qr "^[MDARC]." "$line" && set git_count[2] (math $git_count[2] + 1) + string match -qr "^\?\?" "$line" && set git_count[3] (math $git_count[3] + 1) + string match -qr "^[ADU]{2}" "$line" && set git_count[4] (math $git_count[4] + 1) + end + end + test -n "$git_count[1]" && prompt.add "$color_git[1]" "~$git_count[1]" + test -n "$git_count[2]" && prompt.add "$color_git[2]" "+$git_count[2]" + test -n "$git_count[3]" && prompt.add "$color_git[3]" "!$git_count[3]" + test -n "$git_count[4]" && prompt.add "$color_git[4]" "*$git_count[4]" +end diff --git a/cli/.config/fish/functions/rgrep.fish b/cli/.config/fish/functions/rgrep.fish new file mode 100644 index 0000000..c6be59a --- /dev/null +++ b/cli/.config/fish/functions/rgrep.fish @@ -0,0 +1,3 @@ +function rgrep + grep --exclude-dir=.git -R $argv +end diff --git a/cli/.config/fish/functions/tailf.fish b/cli/.config/fish/functions/tailf.fish new file mode 100644 index 0000000..aaaa956 --- /dev/null +++ b/cli/.config/fish/functions/tailf.fish @@ -0,0 +1,3 @@ +function tailf + command less +F $argv +end diff --git a/cli/.config/fish/functions/tmux.fish b/cli/.config/fish/functions/tmux.fish new file mode 100644 index 0000000..25fff05 --- /dev/null +++ b/cli/.config/fish/functions/tmux.fish @@ -0,0 +1,3 @@ +function tmux + command tmux -2 $argv +end diff --git a/cli/.config/fish/functions/vim.fish b/cli/.config/fish/functions/vim.fish new file mode 100644 index 0000000..d03a51a --- /dev/null +++ b/cli/.config/fish/functions/vim.fish @@ -0,0 +1,3 @@ +function vim + command nvim $argv +end