diff options
author | Arun Prakash Jana <engineerarun@gmail.com> | 2019-11-17 19:14:30 +0530 |
---|---|---|
committer | Arun Prakash Jana <engineerarun@gmail.com> | 2019-11-17 19:14:30 +0530 |
commit | 0620b1dfb5c5e9a66a210c6111ea829f4c5b4ab7 (patch) | |
tree | 4327b4a3fd8b1058df6dd7df5df420e187a0421a /plugins/fzhist | |
parent | 407b690404e60f3c66a8b7bb2b580b8d2e6e61f3 (diff) | |
download | nnn-0620b1dfb5c5e9a66a210c6111ea829f4c5b4ab7.tar.gz |
Plugin fzhist
Diffstat (limited to 'plugins/fzhist')
-rwxr-xr-x | plugins/fzhist | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/plugins/fzhist b/plugins/fzhist new file mode 100755 index 0000000..bad4e2d --- /dev/null +++ b/plugins/fzhist @@ -0,0 +1,31 @@ +#!/usr/bin/env sh + +# Description: Fuzzy find a command from history, edit in $EDITOR and run as a command +# Currently supports only bash and fish history +# +# Shell: POSIX compliant +# Author: Arun Prakash Jana + +shellname="$(basename "$SHELL")" + +if [ "$shellname" = "bash" ]; then + hist_file="$HOME/.bash_history" + entry="$(cat "$hist_file" | fzy)" +elif [ "$shellname" = "fish" ]; then + hist_file="$HOME/.config/fish/fish_history" + entry="$(cat "$hist_file" | grep "\- cmd: " | cut -c 8- | fzy)" +fi + +if ! [ -z "$entry" ]; then + tmpfile=$(mktemp) + echo "$entry" >> $tmpfile + $EDITOR $tmpfile + + cmd="$(cat $tmpfile)" + + if ! [ -z "$cmd" ]; then + $SHELL -c "$cmd" + fi + + rm $tmpfile +fi |