Browse Source

Plugin fzhist

master
Arun Prakash Jana 5 years ago
parent
commit
0620b1dfb5
No known key found for this signature in database GPG Key ID: A75979F35C080412
2 changed files with 32 additions and 0 deletions
  1. +1
    -0
      plugins/README.md
  2. +31
    -0
      plugins/fzhist

+ 1
- 0
plugins/README.md View File

@@ -15,6 +15,7 @@ The currently available plugins are listed below.
| dragdrop | sh | [dragon](https://github.com/mwh/dragon) | Drag/drop files from/into nnn | | dragdrop | sh | [dragon](https://github.com/mwh/dragon) | Drag/drop files from/into nnn |
| exetoggle | sh | chmod | Toggle executable status of hovered file | | exetoggle | sh | chmod | Toggle executable status of hovered file |
| fzcd | sh | fzy/fzf<br>(optional fd) | Change to the directory of a fuzzy-selected file/dir | | fzcd | sh | fzy/fzf<br>(optional fd) | Change to the directory of a fuzzy-selected file/dir |
| fzhist | sh | fzy | Fuzzy-select a cmd from history, edit in $EDITOR and run |
| fzopen | sh | fzy, xdg-open | Fuzzy find a file in dir subtree and edit or xdg-open | | fzopen | sh | fzy, xdg-open | Fuzzy find a file in dir subtree and edit or xdg-open |
| getplugs | sh | curl | Update plugins | | getplugs | sh | curl | Update plugins |
| gutenread | sh | curl, unzip, w3m<br>[epr](https://github.com/wustho/epr) (optional)| Browse, download, read from Project Gutenberg | | gutenread | sh | curl, unzip, w3m<br>[epr](https://github.com/wustho/epr) (optional)| Browse, download, read from Project Gutenberg |


+ 31
- 0
plugins/fzhist View File

@@ -0,0 +1,31 @@
#!/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"
entry="$(cat "$hist_file" | fzy)"
elif [ "$shellname" = "fish" ]; then
hist_file="$HOME/.config/fish/fish_history"
entry="$(cat "$hist_file" | grep "\- cmd: " | cut -c 8- | fzy)"
fi

if ! [ -z "$entry" ]; then
tmpfile=$(mktemp)
echo "$entry" >> $tmpfile
$EDITOR $tmpfile

cmd="$(cat $tmpfile)"

if ! [ -z "$cmd" ]; then
$SHELL -c "$cmd"
fi

rm $tmpfile
fi

Loading…
Cancel
Save