diff options
| author | Anton Bobov <anton@bobov.name> | 2023-10-25 19:17:11 +0500 |
|---|---|---|
| committer | Anton Bobov <anton@bobov.name> | 2023-10-27 14:26:55 +0500 |
| commit | 62c95ef2f3a2374ddda52302d54801cfe442484d (patch) | |
| tree | 8b74bb0bee41cf62bc9149429dac7b0f81123919 /files/.config/nnn/plugins/fzhist | |
| parent | 748cafebaf85b9827c8d3df4535a1a34ddbe82fd (diff) | |
[nnn] Add getplugs plugin and update all plugins
Diffstat (limited to 'files/.config/nnn/plugins/fzhist')
| -rwxr-xr-x | files/.config/nnn/plugins/fzhist | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/files/.config/nnn/plugins/fzhist b/files/.config/nnn/plugins/fzhist new file mode 100755 index 0000000..111bc22 --- /dev/null +++ b/files/.config/nnn/plugins/fzhist @@ -0,0 +1,40 @@ +#!/usr/bin/env sh + +# Description: Fuzzy find a command from history, +# edit in $EDITOR and run as a command +# +# Note: Supports only bash and fish history +# +# Shell: POSIX compliant +# Author: Arun Prakash Jana + +if type fzf >/dev/null 2>&1; then + fuzzy=fzf +else + exit 1 +fi + +shellname="$(basename "$SHELL")" + +if [ "$shellname" = "bash" ]; then + hist_file="$HOME/.bash_history" + entry="$("$fuzzy" < "$hist_file")" +elif [ "$shellname" = "fish" ]; then + hist_file="$HOME/.local/share/fish/fish_history" + entry="$(grep "\- cmd: " "$hist_file" | cut -c 8- | "$fuzzy")" +fi + +if [ -n "$entry" ]; then + tmpfile=$(mktemp) + echo "$entry" >> "$tmpfile" + $EDITOR "$tmpfile" + + if [ -s "$tmpfile" ]; then + $SHELL -c "$(cat "$tmpfile")" + fi + + rm "$tmpfile" + + printf "Press any key to exit" + read -r _ +fi |
