From 3dac035819a88ad366338822c862679754c5b257 Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 15 Sep 2022 17:11:34 -0700 Subject: [PATCH 1/3] slightly improve and optimize n.fish The expr is redundant because `test -ge` treats strings as numbers already. --- misc/quitcd/quitcd.fish | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/misc/quitcd/quitcd.fish b/misc/quitcd/quitcd.fish index c9902080..12d3b6d2 100644 --- a/misc/quitcd/quitcd.fish +++ b/misc/quitcd/quitcd.fish @@ -4,11 +4,9 @@ function n --wraps nnn --description 'support nnn quit and change directory' # Block nesting of nnn in subshells - if test -n "$NNNLVL" - if [ (expr $NNNLVL + 0) -ge 1 ] - echo "nnn is already running" - return - end + if test -n "$NNNLVL" && test $NNNLVL -ge 1 + echo "nnn is already running" + return end # The behaviour is set to cd on quit (nnn checks if NNN_TMPFILE is set) From c9c74dd753d6f833fc77831dd0b1310ff81a389c Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 15 Sep 2022 18:24:04 -0700 Subject: [PATCH 2/3] make one single invocation to test --- misc/quitcd/quitcd.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/quitcd/quitcd.fish b/misc/quitcd/quitcd.fish index 12d3b6d2..952ae169 100644 --- a/misc/quitcd/quitcd.fish +++ b/misc/quitcd/quitcd.fish @@ -4,7 +4,7 @@ function n --wraps nnn --description 'support nnn quit and change directory' # Block nesting of nnn in subshells - if test -n "$NNNLVL" && test $NNNLVL -ge 1 + if test -n "$NNNLVL" -a $NNNLVL -ge 1 echo "nnn is already running" return end From a7ce7bb36cc835cfb3f53b980b1486887a8666e9 Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 15 Sep 2022 19:57:25 -0700 Subject: [PATCH 3/3] wrap in quotes just in case --- misc/quitcd/quitcd.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/quitcd/quitcd.fish b/misc/quitcd/quitcd.fish index 952ae169..a8c3dc43 100644 --- a/misc/quitcd/quitcd.fish +++ b/misc/quitcd/quitcd.fish @@ -4,7 +4,7 @@ function n --wraps nnn --description 'support nnn quit and change directory' # Block nesting of nnn in subshells - if test -n "$NNNLVL" -a $NNNLVL -ge 1 + if test -n "$NNNLVL" -a "$NNNLVL" -ge 1 echo "nnn is already running" return end