My build of nnn with minor changes
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

39 lines
845 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. if which fzf >/dev/null 2>&1; then
  8. fuzzy=fzf
  9. else
  10. exit 1
  11. fi
  12. shellname="$(basename "$SHELL")"
  13. if [ "$shellname" = "bash" ]; then
  14. hist_file="$HOME/.bash_history"
  15. entry="$("$fuzzy" < "$hist_file")"
  16. elif [ "$shellname" = "fish" ]; then
  17. hist_file="$HOME/.config/fish/fish_history"
  18. entry="$(grep "\- cmd: " "$hist_file" | cut -c 8- | "$fuzzy")"
  19. fi
  20. if ! [ -z "$entry" ]; then
  21. tmpfile=$(mktemp)
  22. echo "$entry" >> "$tmpfile"
  23. $EDITOR "$tmpfile"
  24. if [ -s "$tmpfile" ]; then
  25. $SHELL -c "$(cat "$tmpfile")"
  26. fi
  27. rm "$tmpfile"
  28. printf "Press any key to exit"
  29. read -r _
  30. fi