1
0
Fork 0
mirror of https://github.com/jarun/nnn.git synced 2025-03-21 05:49:45 +00:00
nnn/plugins/fzhist

33 lines
758 B
Text
Raw Normal View History

2019-11-17 19:14:30 +05:30
#!/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"
2019-11-21 00:31:39 +05:30
entry="$(fzy < "$hist_file")"
2019-11-17 19:14:30 +05:30
elif [ "$shellname" = "fish" ]; then
hist_file="$HOME/.config/fish/fish_history"
2019-11-21 00:31:39 +05:30
entry="$(grep "\- cmd: " "$hist_file" | cut -c 8- | fzy)"
2019-11-17 19:14:30 +05:30
fi
if ! [ -z "$entry" ]; then
tmpfile=$(mktemp)
echo "$entry" >> $tmpfile
$EDITOR $tmpfile
2019-11-21 00:31:39 +05:30
if [ -s $tmpfile ]; then
$SHELL -c "$(cat $tmpfile)"
2019-11-17 19:14:30 +05:30
fi
rm $tmpfile
2019-11-17 21:56:05 +05:30
echo -n "Press any key to exit"
read input
2019-11-17 19:14:30 +05:30
fi