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.
 
 
 
 
 
 

35 line
784 B

  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. shellname="$(basename "$SHELL")"
  8. if [ "$shellname" = "bash" ]; then
  9. hist_file="$HOME/.bash_history"
  10. entry="$(cat "$hist_file" | fzy)"
  11. elif [ "$shellname" = "fish" ]; then
  12. hist_file="$HOME/.config/fish/fish_history"
  13. entry="$(cat "$hist_file" | grep "\- cmd: " | cut -c 8- | fzy)"
  14. fi
  15. if ! [ -z "$entry" ]; then
  16. tmpfile=$(mktemp)
  17. echo "$entry" >> $tmpfile
  18. $EDITOR $tmpfile
  19. cmd="$(cat $tmpfile)"
  20. if ! [ -z "$cmd" ]; then
  21. $SHELL -c "$cmd"
  22. fi
  23. rm $tmpfile
  24. echo -n "Press any key to exit"
  25. read input
  26. fi