The file selection/multi picker example at least can work with the fzf package alone. There are a bunch of files in shell/ from the tarball that enable a little magic like interactive history support and the inline picker. On Debian they're also installed in /usr/share/doc/fzf/examples/ for sourcing in your .${shell}rc.
No idea about out-of-the-box support for any of the other completions from maddyboo's post :/.
This is cool, I'll definitely add this to my workflow.
What I do is that I have custom bash history (with no limit on how many item there can be), that stores also an active directory, and id of the shell session. Then when I hit ctrl-R, it pipe that history into the fzf in special order: things from my current session history, then from the current directory, and then rest. This means, that if I come 2 months later to some older project and want to remember how to run tests / deploy, I just hit ctrl-r, and I find what I need.
Not GP, and my setup is a great deal less sophisticated than GP's.
However, in my `.bashrc`, I have:
log_bash_persistent_history()
{
[[
$(history 1) =~ ^\ *[0-9]+\ +([^\ ]+\ [^\ ]+)\ +(.*)$
]]
local date_part="${BASH_REMATCH[1]}"
local command_part="${BASH_REMATCH[2]}"
if [ "$command_part" != "$PERSISTENT_HISTORY_LAST" ]
then
echo $date_part "|" "$command_part" >> ~/.persistent_history
export PERSISTENT_HISTORY_LAST="$command_part"
fi
}
# Stuff to do on PROMPT_COMMAND
run_on_prompt_command()
{
log_bash_persistent_history
}
PROMPT_COMMAND="run_on_prompt_command"
HISTTIMEFORMAT="%d/%m/%y %T "
alias phgrep='cat ~/.persistent_history|grep --color'
alias hgrep='history|grep --color'
This doesn't save all of the information like the current shell, working directory, etc... but you could easily modify it to include that information. It also doesn't do all of the context-aware piping, you have to rely on grep. But just having a really good persistent history is itself insanely useful.
My setup was itself stolen from someone else on HN a few years ago, and I've since forgotten their name.
If you want to have just persistent histry (really simple), you can use vanilla bash history something like.
export HISTCONTROL=ignorespace
shopt -s histappend
export HISTSIZE=99999999 # Big enough number to never rotate history (or when you really don't care)
export HISTFILESIZE=99999999
shopt -s checkwinsize
export HISTTIMEFORMAT='%F %T '
It's been really cool to see tools such as tmux, FZF, or Fish make waves on our interactions with the terminal. CLI is such a mature space, tools have to be really great to gain any traction.
I use fish as my main shell. Sometimes I find its documentation a bit obtuse, but I love the sense of humor in its tag line: “a shell for the 90s.” It was first released in 2005.
I'm more partial to a self-contained binary type of solution -- C or Go, in this case. But that toolkit does look like a valuable source of inspiration. Thanks!
Had a similar issue with an in house tool and learned that `click`, the framework we use for CLI's, has built in support for generating auto completions[0].
Could be worth it for others to check if such a feature exists for the framework they're using.
This is really cool! I had something similar with a bunch of pearl scripts at work. Essentially I would call perldoc on them and parse the output to get the command line options. But the fzf addition is a nice touch.
On my Christmas holidays I built a little tool that does similar things.
Features I wanted to include originally were
1 shell completion autogeneration from `--help` texts;
2 support bash/zsh/fish;
3 support toml-like description of command arguments.
At the moment I have a tool that generates completions from `--help` messages and supports bash/zsh. I use it daily and it makes me little bit happier.
Actually when I started this project I used fish as my main shell on laptop and first versions of cod did support fish, but then I decided to focus bash/zsh as they look more popular.
I still want to add fish support when I have some time though. It doesn't look complicated.
There are some discussions about cross-shell autocompletion on the #shell-autocompletion channel of https://oilshell.zulipchat.com/, but it didn't go that far.
The Ion work described in the sibling blog post went the furthest in terms of implementation I think, but I haven't heard anything about it in awhile.
Syntax here is not anything like a well thought out proposal, just a demonstration of what I believe to be a shell agnostic method of describing both 'where can I complete?' and 'how can I compete it?'
I wouldn't want to limit myself like that. The best home spun completions I've written will do things like look up values in a database, differ depending on previous arguments, parse some file, etc. These will never fit into a declarative language.
- of course, command completion
- type `echo $` and press tab - fzf through all your environment variables
- type `command ` and press tab - fzf through all programs available in your PATH
- type `builtin ` and press tab - fzf through all of zsh's builtin functions
- select multiple results at once, they'll be concatenated with spaces
- pick files, with the ability to press / to select a directory and automatically restart fzf-tab inside of it
1: https://github.com/Aloxaf/fzf-tab