diff --git a/fish/.config/fish/config.fish b/fish/.config/fish/config.fish index 4e4cee6..5b03798 100644 --- a/fish/.config/fish/config.fish +++ b/fish/.config/fish/config.fish @@ -256,163 +256,6 @@ alias cbd='cargo doc' alias cbD='cargo doc --open' alias cbu='cargo update' -# Git fzf helper functions -# https://github.com/junegunn/fzf/wiki/Examples-(fish) -function fco -d "Checkout a branch using fzf" - git branch --all | grep -v HEAD | string trim | fzf | read -l result; and git checkout "$result" -end - -function fcoc -d "Checkout a commit using fzf" - git log --pretty=oneline --abbrev-commit --reverse | fzf --tac +s -e | awk '{print $1;}' | read -l result; and git checkout "$result" -end - -# https://gist.github.com/gabesoft/b6e5e959c4cb11ed257d41edb07d47cb -# Modify to use --exact flag for fzf and delta as pager -function fbr --description "Git browse commits" - set -l log_line_to_hash "echo {} | grep -o '[a-f0-9]\{7\}' | head -1" - set -l view_commit "$log_line_to_hash | xargs -I % sh -c 'git show --color=always % | delta | less -R'" - set -l copy_commit_hash "$log_line_to_hash | xclip" - set -l git_checkout "$log_line_to_hash | xargs -I % sh -c 'git checkout %'" - set -l open_cmd "open" - - if test (uname) = Linux - set open_cmd "xdg-open" - end - - set github_open "$log_line_to_hash | xargs -I % sh -c '$open_cmd https://github.\$(git config remote.origin.url | cut -f2 -d. | tr \':\' /)/commit/%'" - - git log --color=always --format='%C(auto)%h%d %s %C(green)%C(bold)%cr% C(blue)%an' | \ - fzf --exact --no-sort --reverse --tiebreak=index --no-multi --ansi \ - --preview="$view_commit" \ - --header="ENTER to view, CTRL-Y to copy hash, CTRL-O to open on GitHub, CTRL-X to checkout, CTRL-C to exit" \ - --bind "enter:execute:$view_commit" \ - --bind "ctrl-y:execute:$copy_commit_hash" \ - --bind "ctrl-x:execute:$git_checkout" \ - --bind "ctrl-o:execute:$github_open" -end - -function fcf --description "Git commit fixup using fzf" - git commit --fixup (git log --pretty=oneline --abbrev-commit --color=always | fzf --ansi | cut -d ' ' -f1) -end - -function fcr --description "Git reset to a selected commit using fzf" - git reset $argv (git log --pretty=oneline --abbrev-commit --color=always | fzf --ansi +s | awk '{print $1}') -end - -function fcR --description "Git revert a selected commit using fzf" - git revert (git log --pretty=oneline --abbrev-commit --color=always | fzf --ansi +s | awk '{print $1}') -end - -function frbi --description "Git interactive rebase using fzf" - git rebase -i (git log --pretty=oneline --abbrev-commit --color=always | fzf --ansi | cut -d ' ' -f1) -end - -function ffa --description "Git add files using fzf" - git add -- (git ls-files --modified --others --exclude-standard | fzf -m --preview 'bat --color=always {}') -end - -function ffco --description "Git checkout a file using fzf" - git checkout $argv -- (git ls-files --modified --exclude-standard | fzf -m) -end - -function ffrs --description "Git restore a staged file using fzf" - git restore --staged $argv -- (git diff --name-only --staged | fzf -m) -end - -function ffr --description "Git restore a file using fzf" - git restore $argv -- (git ls-files --modified --exclude-standard | fzf -m) -end - -function grf --description "Search within a file with grep with context" - grep --color=always -C 10 --group-separator="---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" $argv | less -R -end - -function rgf --description "Search within a file with ripgrep" - rg --color always $argv | nvim -R +AnsiEsc -end - -function rgc --description "Search within a file with ripgrep with context" - rg --color always -C 10 --context-separator="---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" $argv | nvim -R +AnsiEsc -end - -function vo --description "Pipe a command output to neovim" - $argv | nvim -R -end - -function dotp --description "Generate Pipewire dot graph for linked nodes" - pw-dot -L -s -o /tmp/pw.dot - dot -Tsvg /tmp/pw.dot > ~/Pictures/pipewire/pw-dot-(date +%T).svg - rm /tmp/pw.dot -end - -function dotP --description "Generate Pipewire dot graph for all nodes" - pw-dot -L -a -o /tmp/pw.dot - dot -Tsvg /tmp/pw.dot > ~/Pictures/pipewire/pw-dot-(date +%T).svg - rm /tmp/pw.dot -end - -function dotg --description "Generate gstreamer dot graph for selected file" - find $argv -maxdepth 1 -regextype posix-extended -regex ".*\.(dot)" | fzf | read -l result; and dot -Tsvg "$result" -O - mv "$result".svg ~/Pictures/gstreamer -end - -function gdba --description "Attach to a process" - gdb attach -p (ps -ef | fzf | awk '{print $2}' | head -1) -end - -function gdbp --description "Attach to a python process" - gdb python3 (ps -ef | fzf | awk '{print $2}' | head -1) -end - -function gdbr --description "Start a command/process with rust-gdb" - rust-gdb --args $argv -end - -function pst --description "Show process tree of a process" - set proc (ps -ef | fzf | awk '{print $2}' | head -1) - pstree -H $proc $proc -end - -function cdi --description "Select a coredump to run coredumpctl info" - coredumpctl list --reverse | awk -F" " '$9 == "present"' | fzf | read -l result - coredumpctl info (echo $result | awk -F" " '{print $5}') -end - -function cdg --description "coredumpctl gdb on last crashed process" - coredumpctl gdb -end - -function cdG --description "Select a coredump to run coredumpctl gdb" - coredumpctl list --reverse | awk -F" " '$9 == "present"' | fzf | read -l result - coredumpctl gdb (echo $result | awk -F" " '{print $5}') -end - -function pft --description "Select a process to run perf top" - set proc (ps -ef | fzf | awk '{print $2}') - perf top -p $proc -end - -function pfr --description "Select a process to record performance data in given file name" - set proc (ps -ef | fzf | awk '{print $2}') - perf record -F 99 -o $argv -p $proc -end - -function jbl --description "Select a boot to view logs" - journalctl -r -b (journalctl --list-boots | fzf --tac | awk '{print $1}') -end - -function pk --description "Fuzzy find a process to kill" - set proc (ps -ef | fzf | awk '{print $2}') - kill -SIGKILL $proc -end - -function rfc --description "Search for string in RFC documents and open" - if test -e ~/rfc - rg --files-with-matches $argv ~/rfc | fzf | read -l result - nvim -R $result - end -end - fzf_key_bindings starship init fish | source diff --git a/fish/.config/fish/functions/cdG.fish b/fish/.config/fish/functions/cdG.fish new file mode 100644 index 0000000..ac8bbaf --- /dev/null +++ b/fish/.config/fish/functions/cdG.fish @@ -0,0 +1,4 @@ +function cdG --description 'Select a coredump to run coredumpctl gdb' + coredumpctl list --reverse | awk -F" " '$9 == "present"' | fzf | read -l result + coredumpctl gdb (echo $result | awk -F" " '{print $5}') +end diff --git a/fish/.config/fish/functions/cdg.fish b/fish/.config/fish/functions/cdg.fish new file mode 100644 index 0000000..c5d59ea --- /dev/null +++ b/fish/.config/fish/functions/cdg.fish @@ -0,0 +1,3 @@ +function cdg --description 'coredumpctl gdb on last crashed process' + coredumpctl gdb +end diff --git a/fish/.config/fish/functions/cdi.fish b/fish/.config/fish/functions/cdi.fish new file mode 100644 index 0000000..f40fcac --- /dev/null +++ b/fish/.config/fish/functions/cdi.fish @@ -0,0 +1,4 @@ +function cdi --description 'Select a coredump to run coredumpctl info' + coredumpctl list --reverse | awk -F" " '$9 == "present"' | fzf | read -l result + coredumpctl info (echo $result | awk -F" " '{print $5}') +end diff --git a/fish/.config/fish/functions/dotP.fish b/fish/.config/fish/functions/dotP.fish new file mode 100644 index 0000000..9961b5f --- /dev/null +++ b/fish/.config/fish/functions/dotP.fish @@ -0,0 +1,5 @@ +function dotP --description 'Generate Pipewire dot graph for all nodes' + pw-dot -L -a -o /tmp/pw.dot + dot -Tsvg /tmp/pw.dot > ~/Pictures/pipewire/pw-dot-(date +%T).svg + rm /tmp/pw.dot +end diff --git a/fish/.config/fish/functions/dotg.fish b/fish/.config/fish/functions/dotg.fish new file mode 100644 index 0000000..2fb1113 --- /dev/null +++ b/fish/.config/fish/functions/dotg.fish @@ -0,0 +1,4 @@ +function dotg --description 'Generate gstreamer dot graph for selected file' + find $argv -maxdepth 1 -regextype posix-extended -regex ".*\.(dot)" | fzf | read -l result; and dot -Tsvg "$result" -O + mv "$result".svg ~/Pictures/gstreamer +end diff --git a/fish/.config/fish/functions/dotp.fish b/fish/.config/fish/functions/dotp.fish new file mode 100644 index 0000000..a1a9a2e --- /dev/null +++ b/fish/.config/fish/functions/dotp.fish @@ -0,0 +1,5 @@ +function dotp --description 'Generate Pipewire dot graph for linked nodes' + pw-dot -L -s -o /tmp/pw.dot + dot -Tsvg /tmp/pw.dot > ~/Pictures/pipewire/pw-dot-(date +%T).svg + rm /tmp/pw.dot +end diff --git a/fish/.config/fish/functions/fbr.fish b/fish/.config/fish/functions/fbr.fish new file mode 100644 index 0000000..fd5c81a --- /dev/null +++ b/fish/.config/fish/functions/fbr.fish @@ -0,0 +1,22 @@ +function fbr --description 'Git browse commits' + set -l log_line_to_hash "echo {} | grep -o '[a-f0-9]\{7\}' | head -1" + set -l view_commit "$log_line_to_hash | xargs -I % sh -c 'git show --color=always % | delta | less -R'" + set -l copy_commit_hash "$log_line_to_hash | xclip" + set -l git_checkout "$log_line_to_hash | xargs -I % sh -c 'git checkout %'" + set -l open_cmd "open" + + if test (uname) = Linux + set open_cmd "xdg-open" + end + + set github_open "$log_line_to_hash | xargs -I % sh -c '$open_cmd https://github.\$(git config remote.origin.url | cut -f2 -d. | tr \':\' /)/commit/%'" + + git log --color=always --format='%C(auto)%h%d %s %C(green)%C(bold)%cr% C(blue)%an' | \ + fzf --exact --no-sort --reverse --tiebreak=index --no-multi --ansi \ + --preview="$view_commit" \ + --header="ENTER to view, CTRL-Y to copy hash, CTRL-O to open on GitHub, CTRL-X to checkout, CTRL-C to exit" \ + --bind "enter:execute:$view_commit" \ + --bind "ctrl-y:execute:$copy_commit_hash" \ + --bind "ctrl-x:execute:$git_checkout" \ + --bind "ctrl-o:execute:$github_open" +end diff --git a/fish/.config/fish/functions/fcR.fish b/fish/.config/fish/functions/fcR.fish new file mode 100644 index 0000000..e2adff8 --- /dev/null +++ b/fish/.config/fish/functions/fcR.fish @@ -0,0 +1,3 @@ +function fcR --description 'Git revert a selected commit using fzf' + git revert (git log --pretty=oneline --abbrev-commit --color=always | fzf --ansi +s | awk '{print $1}') +end diff --git a/fish/.config/fish/functions/fcf.fish b/fish/.config/fish/functions/fcf.fish new file mode 100644 index 0000000..37a341c --- /dev/null +++ b/fish/.config/fish/functions/fcf.fish @@ -0,0 +1,3 @@ +function fcf --description 'Git commit fixup using fzf' + git commit --fixup (git log --pretty=oneline --abbrev-commit --color=always | fzf --ansi | cut -d ' ' -f1) +end diff --git a/fish/.config/fish/functions/fco.fish b/fish/.config/fish/functions/fco.fish new file mode 100644 index 0000000..9fa1b68 --- /dev/null +++ b/fish/.config/fish/functions/fco.fish @@ -0,0 +1,3 @@ +function fco --description 'Checkout a branch using fzf' + git branch --all | grep -v HEAD | string trim | fzf | read -l result; and git checkout "$result" +end diff --git a/fish/.config/fish/functions/fcoc.fish b/fish/.config/fish/functions/fcoc.fish new file mode 100644 index 0000000..5ca45be --- /dev/null +++ b/fish/.config/fish/functions/fcoc.fish @@ -0,0 +1,3 @@ +function fcoc --description 'Checkout a commit using fzf' + git log --pretty=oneline --abbrev-commit --reverse | fzf --tac +s -e | awk '{print $1;}' | read -l result; and git checkout "$result" +end diff --git a/fish/.config/fish/functions/fcr.fish b/fish/.config/fish/functions/fcr.fish new file mode 100644 index 0000000..7f1ba23 --- /dev/null +++ b/fish/.config/fish/functions/fcr.fish @@ -0,0 +1,3 @@ +function fcr --description 'Git reset to a selected commit using fzf' + git reset $argv (git log --pretty=oneline --abbrev-commit --color=always | fzf --ansi +s | awk '{print $1}') +end diff --git a/fish/.config/fish/functions/ffa.fish b/fish/.config/fish/functions/ffa.fish new file mode 100644 index 0000000..d42553b --- /dev/null +++ b/fish/.config/fish/functions/ffa.fish @@ -0,0 +1,3 @@ +function ffa --description 'Git add files using fzf' + git add -- (git ls-files --modified --others --exclude-standard | fzf -m --preview 'bat --color=always {}') +end diff --git a/fish/.config/fish/functions/ffco.fish b/fish/.config/fish/functions/ffco.fish new file mode 100644 index 0000000..a8b92ae --- /dev/null +++ b/fish/.config/fish/functions/ffco.fish @@ -0,0 +1,3 @@ +function ffco --description 'Git checkout a file using fzf' + git checkout $argv -- (git ls-files --modified --exclude-standard | fzf -m) +end diff --git a/fish/.config/fish/functions/ffr.fish b/fish/.config/fish/functions/ffr.fish new file mode 100644 index 0000000..00147cc --- /dev/null +++ b/fish/.config/fish/functions/ffr.fish @@ -0,0 +1,3 @@ +function ffr --description 'Git restore a file using fzf' + git restore $argv -- (git ls-files --modified --exclude-standard | fzf -m) +end diff --git a/fish/.config/fish/functions/ffrs.fish b/fish/.config/fish/functions/ffrs.fish new file mode 100644 index 0000000..dcc9ef4 --- /dev/null +++ b/fish/.config/fish/functions/ffrs.fish @@ -0,0 +1,3 @@ +function ffrs --description 'Git restore a staged file using fzf' + git restore --staged $argv -- (git diff --name-only --staged | fzf -m) +end diff --git a/fish/.config/fish/functions/frbi.fish b/fish/.config/fish/functions/frbi.fish new file mode 100644 index 0000000..c052687 --- /dev/null +++ b/fish/.config/fish/functions/frbi.fish @@ -0,0 +1,3 @@ +function frbi --description 'Git interactive rebase using fzf' + git rebase -i (git log --pretty=oneline --abbrev-commit --color=always | fzf --ansi | cut -d ' ' -f1) +end diff --git a/fish/.config/fish/functions/gdba.fish b/fish/.config/fish/functions/gdba.fish new file mode 100644 index 0000000..b354bab --- /dev/null +++ b/fish/.config/fish/functions/gdba.fish @@ -0,0 +1,3 @@ +function gdba --description 'Attach to a process' + gdb attach -p (ps -ef | fzf | awk '{print $2}' | head -1) +end diff --git a/fish/.config/fish/functions/gdbp.fish b/fish/.config/fish/functions/gdbp.fish new file mode 100644 index 0000000..e53e1be --- /dev/null +++ b/fish/.config/fish/functions/gdbp.fish @@ -0,0 +1,3 @@ +function gdbp --description 'Attach to a python process' + gdb python3 (ps -ef | fzf | awk '{print $2}' | head -1) +end diff --git a/fish/.config/fish/functions/gdbr.fish b/fish/.config/fish/functions/gdbr.fish new file mode 100644 index 0000000..bacca51 --- /dev/null +++ b/fish/.config/fish/functions/gdbr.fish @@ -0,0 +1,3 @@ +function gdbr --description 'Start a command/process with rust-gdb' + rust-gdb --args $argv +end diff --git a/fish/.config/fish/functions/grf.fish b/fish/.config/fish/functions/grf.fish new file mode 100644 index 0000000..e015a9b --- /dev/null +++ b/fish/.config/fish/functions/grf.fish @@ -0,0 +1,3 @@ +function grf --description 'Search within a file with grep with context' + grep --color=always -C 10 --group-separator="---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" $argv | less -R +end diff --git a/fish/.config/fish/functions/jbl.fish b/fish/.config/fish/functions/jbl.fish new file mode 100644 index 0000000..7ea931a --- /dev/null +++ b/fish/.config/fish/functions/jbl.fish @@ -0,0 +1,3 @@ +function jbl --description 'Select a boot to view logs' + journalctl -r -b (journalctl --list-boots | fzf --tac | awk '{print $1}') +end diff --git a/fish/.config/fish/functions/pfr.fish b/fish/.config/fish/functions/pfr.fish new file mode 100644 index 0000000..8cb1e7a --- /dev/null +++ b/fish/.config/fish/functions/pfr.fish @@ -0,0 +1,4 @@ +function pfr --description 'Select a process to record performance data in given file name' + set proc (ps -ef | fzf | awk '{print $2}') + perf record -F 99 -o $argv -p $proc +end diff --git a/fish/.config/fish/functions/pft.fish b/fish/.config/fish/functions/pft.fish new file mode 100644 index 0000000..ecb5e14 --- /dev/null +++ b/fish/.config/fish/functions/pft.fish @@ -0,0 +1,4 @@ +function pft --description 'Select a process to run perf top' + set proc (ps -ef | fzf | awk '{print $2}') + perf top -p $proc +end diff --git a/fish/.config/fish/functions/pk.fish b/fish/.config/fish/functions/pk.fish new file mode 100644 index 0000000..a2ed2db --- /dev/null +++ b/fish/.config/fish/functions/pk.fish @@ -0,0 +1,4 @@ +function pk --description 'Fuzzy find a process to kill' + set proc (ps -ef | fzf | awk '{print $2}') + kill -SIGKILL $proc +end diff --git a/fish/.config/fish/functions/pst.fish b/fish/.config/fish/functions/pst.fish new file mode 100644 index 0000000..7bdb2d6 --- /dev/null +++ b/fish/.config/fish/functions/pst.fish @@ -0,0 +1,4 @@ +function pst --description 'Show process tree of a process' + set proc (ps -ef | fzf | awk '{print $2}' | head -1) + pstree -H $proc $proc +end diff --git a/fish/.config/fish/functions/rfc.fish b/fish/.config/fish/functions/rfc.fish new file mode 100644 index 0000000..fd741b5 --- /dev/null +++ b/fish/.config/fish/functions/rfc.fish @@ -0,0 +1,6 @@ +function rfc --description 'Search for string in RFC documents and open' + if test -e ~/rfc + rg --files-with-matches $argv ~/rfc | fzf | read -l result + nvim -R $result + end +end diff --git a/fish/.config/fish/functions/rgc.fish b/fish/.config/fish/functions/rgc.fish new file mode 100644 index 0000000..7b47099 --- /dev/null +++ b/fish/.config/fish/functions/rgc.fish @@ -0,0 +1,3 @@ +function rgc --description 'Search within a file with ripgrep with context' + rg --color always -C 10 --context-separator="---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" $argv | nvim -R +AnsiEsc +end diff --git a/fish/.config/fish/functions/rgf.fish b/fish/.config/fish/functions/rgf.fish new file mode 100644 index 0000000..14eae51 --- /dev/null +++ b/fish/.config/fish/functions/rgf.fish @@ -0,0 +1,3 @@ +function rgf --description 'Search within a file with ripgrep' + rg --color always $argv | nvim -R +AnsiEsc +end diff --git a/fish/.config/fish/functions/vo.fish b/fish/.config/fish/functions/vo.fish new file mode 100644 index 0000000..7a933ab --- /dev/null +++ b/fish/.config/fish/functions/vo.fish @@ -0,0 +1,3 @@ +function vo --description 'Pipe a command output to neovim' + $argv | nvim -R +end