1
0
Fork 0

fish: some functions and aliases

This commit is contained in:
Von Random 2023-02-05 22:13:01 +02:00
parent 077a885d2a
commit 331c9b0e69
24 changed files with 115 additions and 40 deletions

View file

@ -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

View file

@ -0,0 +1,3 @@
function atmux
tmux attach || tmux
end

View file

@ -0,0 +1,3 @@
function diff
command diff --color $argv
end

View file

@ -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

View file

@ -0,0 +1,3 @@
function g
command lazygit $argv
end

View file

@ -0,0 +1,3 @@
function gci
command git commit $argv
end

View file

@ -0,0 +1,3 @@
function grep
command grep --color=auto $argv
end

View file

@ -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

View file

@ -0,0 +1,4 @@
function groot
set -l root (command git rev-parse --show-toplevel)
test $status -eq 0 && cd $root
end

View file

@ -0,0 +1,3 @@
function gsi
tig status
end

View file

@ -0,0 +1,3 @@
function gsl
command git stash list $argv
end

View file

@ -0,0 +1,3 @@
function gss
command git status -sbu $argv
end

View file

@ -0,0 +1,3 @@
function gsw
command git switch $argv
end

View file

@ -0,0 +1,3 @@
function gup
command git pull $argv
end

View file

@ -0,0 +1,3 @@
function gwta
command git worktree add $argv
end

View file

@ -0,0 +1,3 @@
function gwtp
command git worktree purge $argv
end

View file

@ -0,0 +1,3 @@
function ll
ls -alg $argv
end

View file

@ -0,0 +1,3 @@
function ls
command exa --group-directories-first $argv
end

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,3 @@
function rgrep
grep --exclude-dir=.git -R $argv
end

View file

@ -0,0 +1,3 @@
function tailf
command less +F $argv
end

View file

@ -0,0 +1,3 @@
function tmux
command tmux -2 $argv
end

View file

@ -0,0 +1,3 @@
function vim
command nvim $argv
end