git-sel-changed and git-edit-changed: use fzf to select from changed files in a git repo. git-edit-changed just wraps git-sel-changed.
VimwikiMakeLink: use fzf to select a page / tag to link to in my vimwiki setup.
,f: a vim keybinding to quickly open files by way of fzf
,F bound to FragmentMenu: include output from a fzf menu of scripts starting with fragment-. Date formats, brief markup templates, text decorations, etc.
Of these, I use h and the vim stuff by far the most, but it’s a great general pattern and I should extend it to other things.
Relatedly, rofi works pretty well for doing similar tasks under X. More or less a nicer replacement for dmenu.
First, in .zshrc, keep a log of directory history:
# Record directory history to a simple text file:
function chpwd {
echo "$PWD" >> ~/.directory_history
}
I haven’t solved keeping the history for Bash, since I rarely use it on my desktop machine, but SO has Is there a hook in Bash to find out when the cwd changes? which suggests that wrapping cd in a function could work well enough:
function cd() {
builtin cd $@
chpwd
}
Next, define h and b themselves. In a file that’s sourced by both Bash or ZSH, so should work fine in .zshrc or .bashrc:
# Jump around in recent directory history - takes an optional query string:
function h {
if [ ! -z "$@" ]; then
cd "$(tail -2500 ~/.directory_history | tac | awk '!x[$0]++' | fzf --no-sort --height=50% -q $@)"
else
cd "$(tail -2500 ~/.directory_history | tac | awk '!x[$0]++' | fzf --no-sort --height=50%)"
fi
}
# Bookmark list - if given a parameter, treats it as a path to add to the list:
function b {
if [ ! -z "$@" ]; then
echo "$(realpath "$@")" >> ~/.directory_bookmarks
else
cd "$(sort ~/.directory_bookmarks | uniq | fzf --no-sort --height=50%)"
fi
}
The awk '!x[$0]++' bit is handy for a bunch of stuff - I actually keep it in ~/bin/unsorted-unique. Just filters out duplicates from the list.
Edits: Noticed I could use some extra quoting around directory names in h() and b().
I love this! I’ve been using FZF in vim for ages but I really need to add it to my shell workflow.
A suggestion: I prefer BLOG/1232-add-a-verbose-flag-to-the-startup-script as slash placement because then you can do tree .git/refs/heads and see your branches broken down by Jira project. I wrote a git-tree helper to do that
First, there is no convenient CLI tool like gh to communicate with the JIRA API
True, there isn’t an official one, but go-jira exists and has been very useful. You can create custom templates and commands for its output so you could easily set up a jira command with output suitable for piping to fzf.
I do this extensively in scripts for cloning Git repos, downloading files from cloud storage (see also: rclone), managing plain-text to-do lists, the works. I used Gary Bernhardt’s selecta in all these scripts or years, and recently moved over to fzf with very little fiddling.
This is a really well written post with some great use cases. It also captures beautifully the essence of a shell, for me - the continuum between a command prompt and a script.
Specifically this post has opened the door to the next chapter in my fzf learning, namely the preview mechanism.
I don’t think any other single cli tool has ever had such a big and positive impact on my workflow than fzf has, it’s really a great piece of work.
Your comment prompted me to buy
fzf
’s author a coffee or two https://twitter.com/qmacro/status/1377225451995852802I need to do this sort of thing more often.
Thanks for the prompt, I did similar.
I think that’s a good idea and I will do so also :)
A handful from my setup:
h
: navigate through directory historyb
: bookmark directory paths, jump to bookmarksgit-sel-changed
andgit-edit-changed
: use fzf to select from changed files in a git repo.git-edit-changed
just wrapsgit-sel-changed
.VimwikiMakeLink
: use fzf to select a page / tag to link to in my vimwiki setup.,f
: a vim keybinding to quickly open files by way of fzf,F
bound to FragmentMenu: include output from a fzf menu of scripts starting withfragment-
. Date formats, brief markup templates, text decorations, etc.Of these, I use
h
and the vim stuff by far the most, but it’s a great general pattern and I should extend it to other things.Relatedly, rofi works pretty well for doing similar tasks under X. More or less a nicer replacement for dmenu.
mind sharing how you set up
h
andb
?First, in
.zshrc
, keep a log of directory history:I haven’t solved keeping the history for Bash, since I rarely use it on my desktop machine, but SO has Is there a hook in Bash to find out when the cwd changes? which suggests that wrapping
cd
in a function could work well enough:Next, define
h
andb
themselves. In a file that’s sourced by both Bash or ZSH, so should work fine in.zshrc
or.bashrc
:The
awk '!x[$0]++'
bit is handy for a bunch of stuff - I actually keep it in~/bin/unsorted-unique
. Just filters out duplicates from the list.Edits: Noticed I could use some extra quoting around directory names in
h()
andb()
.Small note,
gh
now supports a--jq
parameter that can parsejq
syntax so you don’t need the CLI tool separately.I love this! I’ve been using FZF in vim for ages but I really need to add it to my shell workflow.
A suggestion: I prefer
BLOG/1232-add-a-verbose-flag-to-the-startup-script
as slash placement because then you can dotree .git/refs/heads
and see your branches broken down by Jira project. I wrote agit-tree
helper to do thatThis is a pretty great set of examples.
One thing: the article says
True, there isn’t an official one, but go-jira exists and has been very useful. You can create custom templates and commands for its output so you could easily set up a
jira
command with output suitable for piping tofzf
.I do this extensively in scripts for cloning Git repos, downloading files from cloud storage (see also:
rclone
), managing plain-text to-do lists, the works. I used Gary Bernhardt’sselecta
in all these scripts or years, and recently moved over tofzf
with very little fiddling.I was inspired to write a post of my own on this subject: SAP Tech Bytes: Exploring SAP-samples with gh and fzf
This is a really well written post with some great use cases. It also captures beautifully the essence of a shell, for me - the continuum between a command prompt and a script.
Specifically this post has opened the door to the next chapter in my
fzf
learning, namely the preview mechanism.FZF is my RSS reader. It’s pretty good too, the lack of read/unread tracking is a feature for me and you get a free “unified” view of your items