My build of nnn with minor changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fzhist 896 B

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env sh
  2. # Description: Fuzzy find a command from history, edit in $EDITOR and run as a command
  3. # Currently supports only bash and fish history
  4. #
  5. # Shell: POSIX compliant
  6. # Author: Arun Prakash Jana
  7. if which fzf >/dev/null 2>&1; then
  8. fuzzy=fzf
  9. elif which fzy >/dev/null 2>&1; then
  10. fuzzy=fzy
  11. else
  12. exit 1
  13. fi
  14. shellname="$(basename "$SHELL")"
  15. if [ "$shellname" = "bash" ]; then
  16. hist_file="$HOME/.bash_history"
  17. entry="$("$fuzzy" < "$hist_file")"
  18. elif [ "$shellname" = "fish" ]; then
  19. hist_file="$HOME/.config/fish/fish_history"
  20. entry="$(grep "\- cmd: " "$hist_file" | cut -c 8- | "$fuzzy")"
  21. fi
  22. if ! [ -z "$entry" ]; then
  23. tmpfile=$(mktemp)
  24. echo "$entry" >> "$tmpfile"
  25. $EDITOR "$tmpfile"
  26. if [ -s "$tmpfile" ]; then
  27. $SHELL -c "$(cat "$tmpfile")"
  28. fi
  29. rm "$tmpfile"
  30. printf "Press any key to exit"
  31. read -r _
  32. fi