Comments (19)
I've just merged support for zsh completions, it will be released in the next version of zoxide. Sorry this took so long, but this is finally an implementation that I'm happy with!
# press <space><tab> to start interactive completions.
z foo<tab> # shows the same completions as cd
z foo<space><tab> # shows interactive completions via zoxide
from zoxide.
Could the tab autocomplete be compatible with bash ? Globally I think it should be handled by xoxide independently of the used shell.
Side note: I confirm, it is awesome 😍
from zoxide.
FWIW, although my skills are limited, here is a bash completion I put together. It only completes with zq value (a list would be better) and the options.
_zoxide_completion() {
local cur prev words cword
_init_completion || return
COMPREPLY=()
case $prev in
-takes_file)
_filedir
return
;;
esac
case ${cur} in
-*)
COMPREPLY=($(compgen -W '
-V --version
-h --help
-i --interactive
' -- "${cur}"; ))
[[ COMPREPLY == *= ]] || compopt +o nospace
;;
*)
# set -x
# COMPREPLY=($(compgen -W "$( zq "${cur}" | awk '{ print $NF}' )" -- "${cur}") )
COMPREPLY=($(compgen -W "$( zq "${cur}" | awk '{ print $NF}' )
" ) )
;;
esac
} && complete -F _zoxide_completion -o nospace z
from zoxide.
If i haven't typed anything, z should work like cd (as it does now)
If i've typed something, it should absolutely cycle through top suggestions, pretty please! Guessing what the top suggestion is, and what additional letters to type to get the right one, is no fun.
EDIT: Actually listing and not cycling would give me everything i want. Same way cd lists all potential completions. z can do the same, and as long as the top match, the one that will be selected if i press enter, is first, that's all the information i'm looking for.
I type: z ex
and press tab.
I see:
~/Documents/example
~/Pictures/exes
/media/files/example
If i'm looking for /media/files/example
i know to press space and fi
to jump to the right place. If i'm looking for ~/Pictures/exes
i know to type an e
. If i'm looking for ~/Documents/example
i know i can just press enter already. Without this essential feedback, i'm jumping blindly to what i hope is the folder i intend.
from zoxide.
For anyone interested, take a look at #257. I've only implemented Bash completions at the moment, but I'd love to know what you think:
- Completions only work when there is one word (therefore completions are always valid).
- By default, it uses the same completions as
cd
. - If the query ends with
**
, it opens upfzf
and does an interactive search (similar to fzf's builtin completions).
If it works well, we can hopefully write completions for other shells in line with this. For now, you can test it out like so:
cargo install --git https://github.com/ajeetdsouza/zoxide --branch bashcomp
Update: Fish completions are done too.
from zoxide.
Two things:
- I think completion for all supported shells should be created, eventually.
- I think that the tab completion should complete the closest match (e.g. what would display when you
zoxide query
the path) and cycle through all subsequent matches.
from zoxide.
I've used the solution provided by @fourjay and it is almost there, except maybe fuzzy path look up, which I think need to be supported within zoxide(because zoxide query does not provide a fuzzy search flag). I can see this is already raised in #34 .
from zoxide.
In the event folks are still looking at this, I've added support for the new query function to the completion
The sed parses out a subpath match. It's not perfect, but it's useful
The awk reformats to a nicer display for the competion popup
the mapfile is bash idiom to embed spaces in the COMPREPLY
The major change is in the catchall (the guts of the completion)
mapfile -t _completions < <( zoxide query --list --score "${cur}" |
sed 's|^[ ]*\([0-9]\+[ ]*\)\(.*/\(.*t.*\).*\)|\3 \2 \1|' |
awk '{printf( "%-17.15s %35.35s %15s |\n", $1, $2, $3) }'
)
IFS=$'\n' COMPREPLY=(${_completions[@]})
unset _completions
from zoxide.
FWIW, I've not been using my attempt (much)
That said, I think the primary use case here is discovery.
Two sub points:
- completion is a standard discovery mechanism across a lot of shell commands.
Yes, there are app specific ways to get similar results, but some (many) of us are reasonably conditioned to mash tab :-) - It's still useful to see what other matches a given (fuzzy) string might have.
Two subcases here:
a) when there's a second match that on a new entry in the frecent Db.
Completion gives easy view of the potential matches
b) when not sure of what other entries are in the Db.
from zoxide.
@fourjay as you suggested, I had a look at how fzf is doing completions, and I think it works quite well for zoxide:
- By default,
z
completions are the same ascd
. It only completes actual directory names. - If the query ends in
**
(customizable), we can switch to anfzf
completer, similar to thezi
command. We can come up with better defaults forzi
to not let it occupy the whole screen. - If the query has more than one word, it cannot be completed correctly, so there would be no completions.
Since fzf already has completions that work like this on a variety of common UNIX commands (vim
, kill
, etc.) which are quite popular, I think it's a reasonably good default for a project like zoxide. @kidonng, I'd love your thoughts on this too.
So, for example, if you were in /home/foo
:
z Do<TAB>
will open the standard autocompleter and give you results likeDocuments/
andDownloads/
, similar tocd
.z Do**<TAB>
will open upfzf
and give you results like/home/foo/git/Dotfiles
in an interactive menu.
I think this approach would be the most consistent, since it segregates the completions for "z as a cd command"
from the "z as an autojumper"
. The only downside is that the *
character is difficult to type, but I'm willing to live with that since it would be customizable by the user.
@mlncn I've thought about what you described, but I don't think it would work for everyone since I myself often use z ex<TAB>
to see what's inside the current folder, and it would be quite messy and confusing if zoxide results got added there. I suspect you might like zsh-autocomplete
, though.
from zoxide.
I think this would be a great feature. I'm not too familiar with setting up shell completions, though, so it might take a while for this feature to land.
from zoxide.
@fourjay Perhaps send a PR?
from zoxide.
Related: marlonrichert/zsh-autocomplete has added support for zoxide.
from zoxide.
This should be relatively easy to implement via clap
(via structopt
), since clap
has native support for generating completions for several popular shells: https://docs.rs/clap/2.33.3/clap/struct.App.html#method.gen_completions_to
from zoxide.
I tried playing around with z
completions today on two different shells. Here's what I found:
- On Elvish, if you type in
z arg
, Elvish expects completions to only start witharg
. For this reason, Elvish cannot supportz
completions, since we will be supplying/absolute/paths/that/match/arg
. - Fish allows arbitrary completions, but the experience is still unintuitive:
- If you type
z
and hit TAB, all the results would start with/
(since they're all absolute paths) - so Fish fills in that/
for you. You have to manually delete the/
before proceeding. The solution is to disable completions if the user hasn't typed anything. - If you type in
z foo bar
, Fish will only use the completions to replacebar
. So you end up with something likez foo /home/bar
which doesn't work. The solution here seems to be not providing completions if there's more than one argument. z
also acts as a regularcd
command. Are the regular cd-able directories expected to show up on top of the list, above the directories retrieved from zoxide? That looks very odd / inconsistent.
- If you type
So far, I'm still not convinced that this would be a useful feature to have.
from zoxide.
Thinking about this a little more, fzf completion fills this role pretty well....
But from an overall consistency perspective, I'd prefer it could be triggered via tab
A little google, and I see that junegunn has already done some work along that line
https://github.com/junegunn/fzf#fuzzy-completion-for-bash-and-zsh
from zoxide.
paste code below in your .zshrc can support z completions
@ajeetdsouza
_zoxide_zsh_tab_completion() {
(( $+compstate )) && compstate[insert]=menu
local keyword="${words:2}"
local completions=(${(@f)"$(zoxide query -l "$keyword")"})
if [[ ${#completions[@]} == 0 ]]; then
_files -/
else
compadd -U -V z "${(@)completions}"
fi
}
if [ "${+functions[compdef]}" -ne 0 ]; then
compdef _zoxide_zsh_tab_completion z 2> /dev/null
fi
from zoxide.
hmm... completions don't seem to be doing anything other than the default for me on zsh. 0.7.5
zinit wait has"zoxide" atinit'eval "$(zoxide init zsh --hook pwd --cmd cd)"' for zdharma/null
from zoxide.
This doesn't properly work for me like it works for cd. I'm using the following zsh completion:
zstyle ':completion:*' completer _expand _expand_alias _complete _correct _ignored _approximate
Which allows me to complete the hello_world
directory by doing cd hwo<TAB>
, however z hwo<TAB>
doesn't work. How can I obtain that result?
Edit: may be the issue described in #513
from zoxide.
Related Issues (20)
- (403) Forbidden while `choco install zoxide` HOT 1
- Error whilst installing zioxid in zsh on warp terminal HOT 3
- Any Good Issues for 1st Timers? HOT 1
- error after installation if PROMPT_COMMAND is altered HOT 5
- Zoxide not adding to db.zo unless you run init again HOT 8
- "no options following" not implemented
- smart autocomplete from zsh HOT 1
- `z <directory>` will jump to entry in database whereas `z <directory>\` will jump to subdirectory <directory> is not Working HOT 4
- sudden zstyle issues with zoxide 0.9.4 HOT 5
- using --cmd with init in fish config configuration doesn't replace the cd command HOT 8
- Fish cd aliasing HOT 3
- Using `cd` as --cmd argument results in infinite loop in bash HOT 1
- maximum nested function level reached error HOT 1
- [fixed] How do I actually use this? HOT 1
- zsh autocomplete is not working HOT 2
- Feature request: Add an option to import from Oh My Zsh’s scd HOT 2
- Substitute and not go to the directory when _ZO_ECHO='1' HOT 2
- Case-sensitivity issues with zoxide database? HOT 1
- Latest change to fish.txt template breaks zoxide HOT 2
- `cd` adds all browsed directories to the database HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zoxide.