From 7310c77f7833e41baa495bb2296a3445e0d5a2aa Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Mon, 26 Dec 2022 14:46:31 +0530 Subject: [PATCH] fish: functions: Check return result of fzf selection --- fish/.config/fish/functions/cdG.fish | 4 +++- fish/.config/fish/functions/cdi.fish | 4 +++- fish/.config/fish/functions/pfr.fish | 4 +++- fish/.config/fish/functions/pft.fish | 4 +++- fish/.config/fish/functions/pk.fish | 4 +++- fish/.config/fish/functions/psmem.fish | 4 +++- fish/.config/fish/functions/pst.fish | 4 +++- fish/.config/fish/functions/rfc.fish | 4 +++- fish/.config/fish/functions/ta.fish | 4 +++- fish/.config/fish/functions/topf.fish | 4 +++- 10 files changed, 30 insertions(+), 10 deletions(-) diff --git a/fish/.config/fish/functions/cdG.fish b/fish/.config/fish/functions/cdG.fish index b794121..150038a 100644 --- a/fish/.config/fish/functions/cdG.fish +++ b/fish/.config/fish/functions/cdG.fish @@ -1,4 +1,6 @@ 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}') + if test -n "$result" + coredumpctl gdb (echo $result | awk -F" " '{print $5}') + end end diff --git a/fish/.config/fish/functions/cdi.fish b/fish/.config/fish/functions/cdi.fish index 6566376..3537597 100644 --- a/fish/.config/fish/functions/cdi.fish +++ b/fish/.config/fish/functions/cdi.fish @@ -1,4 +1,6 @@ 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}') + if test -n "$result" + coredumpctl info (echo $result | awk -F" " '{print $5}') + end end diff --git a/fish/.config/fish/functions/pfr.fish b/fish/.config/fish/functions/pfr.fish index e6cefeb..3649d51 100644 --- a/fish/.config/fish/functions/pfr.fish +++ b/fish/.config/fish/functions/pfr.fish @@ -1,4 +1,6 @@ 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 + if test -n "$proc" + perf record -F 99 -o $argv -p $proc + end end diff --git a/fish/.config/fish/functions/pft.fish b/fish/.config/fish/functions/pft.fish index ac17ea0..c114106 100644 --- a/fish/.config/fish/functions/pft.fish +++ b/fish/.config/fish/functions/pft.fish @@ -1,4 +1,6 @@ function pft --description 'Select a process to run perf top' set proc (ps -ef | fzf | awk '{print $2}') - perf top -p $proc + if test -n "$proc" + perf top -p $proc + end end diff --git a/fish/.config/fish/functions/pk.fish b/fish/.config/fish/functions/pk.fish index b055133..c45467c 100644 --- a/fish/.config/fish/functions/pk.fish +++ b/fish/.config/fish/functions/pk.fish @@ -1,4 +1,6 @@ function pk --description 'Fuzzy find a process to kill' set proc (ps -ef | fzf | awk '{print $2}') - kill -SIGKILL $proc + if test -n "$proc" + kill -SIGKILL $proc + end end diff --git a/fish/.config/fish/functions/psmem.fish b/fish/.config/fish/functions/psmem.fish index 510ad75..366e5b6 100644 --- a/fish/.config/fish/functions/psmem.fish +++ b/fish/.config/fish/functions/psmem.fish @@ -1,4 +1,6 @@ function psmem --description 'Show memory usage of a process' set proc (ps -ef | fzf | awk '{print $2}') - ps_mem -p $proc + if test -n "$proc" + ps_mem -p $proc + end end diff --git a/fish/.config/fish/functions/pst.fish b/fish/.config/fish/functions/pst.fish index 90de9c6..257bed7 100644 --- a/fish/.config/fish/functions/pst.fish +++ b/fish/.config/fish/functions/pst.fish @@ -1,4 +1,6 @@ function pst --description 'Show process tree of a process' set proc (ps -ef | fzf | awk '{print $2}' | head -1) - pstree -H $proc $proc + if test -n "$proc" + pstree -H $proc $proc + end end diff --git a/fish/.config/fish/functions/rfc.fish b/fish/.config/fish/functions/rfc.fish index a9da827..30710ea 100644 --- a/fish/.config/fish/functions/rfc.fish +++ b/fish/.config/fish/functions/rfc.fish @@ -1,6 +1,8 @@ function rfc --description 'Search for string in RFC documents and open' if test -e ~/rfc rg --files-with-matches $argv ~/rfc | fzf --preview='less {}' | read -l result - nvim -R $result + if test -n "$result" + nvim -R $result + end end end diff --git a/fish/.config/fish/functions/ta.fish b/fish/.config/fish/functions/ta.fish index 45f9a56..ea19eba 100644 --- a/fish/.config/fish/functions/ta.fish +++ b/fish/.config/fish/functions/ta.fish @@ -1,4 +1,6 @@ function ta --description 'Attaches to a selected session' set session (tmux list-sessions | fzf | awk -F':' '{print $1}') - tmux attach -t $session + if test -n "$session" + tmux attach -t $session + end end diff --git a/fish/.config/fish/functions/topf.fish b/fish/.config/fish/functions/topf.fish index 58cb2ca..ddd85ea 100644 --- a/fish/.config/fish/functions/topf.fish +++ b/fish/.config/fish/functions/topf.fish @@ -1,4 +1,6 @@ function topf --description 'Select a process to run top' set proc (ps -ef | fzf | awk '{print $2}') - top -H -p $proc + if test -n "$proc" + top -H -p $proc + end end