]> Sergey Matveev's repositories - nnn.git/commitdiff
fzhist plugin: add support for zsh history #1721 (#1722)
authorSyed Umar Anis <umaranis@users.noreply.github.com>
Thu, 7 Sep 2023 12:33:01 +0000 (22:33 +1000)
committerGitHub <noreply@github.com>
Thu, 7 Sep 2023 12:33:01 +0000 (18:03 +0530)
* fzhist plugin: add support for zsh history

* fzhist plugin: check $HISTFILE for history file location

* fzhist plugin: remove extra trailing spaces

plugins/fzhist

index 111bc22c6edc9fcce9190a509bf0193a59d4d0c1..bdfd9296cfd0a99f9456b8805068330ea111768d 100755 (executable)
@@ -3,7 +3,9 @@
 # Description: Fuzzy find a command from history,
 #              edit in $EDITOR and run as a command
 #
-# Note: Supports only bash and fish history
+# Note: Supports only bash, zsh and fish history
+#
+# TODO: For zsh there's also $ZDOTDIR which might need to be checked as well for the -z $HISTFILE && -n $ZDOTDIR case.
 #
 # Shell: POSIX compliant
 # Author: Arun Prakash Jana
@@ -17,7 +19,18 @@ fi
 shellname="$(basename "$SHELL")"
 
 if [ "$shellname" = "bash" ]; then
-    hist_file="$HOME/.bash_history"
+    if [ -f "$HISTFILE" ]; then
+        hist_file="$HISTFILE"
+    else
+        hist_file="$HOME/.bash_history"
+    fi
+    entry="$("$fuzzy" < "$hist_file")"
+elif [ "$shellname" = "zsh" ]; then
+    if [ -f "$HISTFILE" ]; then
+        hist_file="$HISTFILE"
+    else
+        hist_file="$HOME/.zsh_history"
+    fi
     entry="$("$fuzzy" < "$hist_file")"
 elif [ "$shellname" = "fish" ]; then
     hist_file="$HOME/.local/share/fish/fish_history"