homerours / jumper

Accurate and fast files/directories' jumper
MIT License
33 stars 0 forks source link

Unable to do `alias zi = 'jumper-find-dir'` #2

Closed jemorriso closed 4 months ago

jemorriso commented 4 months ago

Hi,

I would love to be able to make an alias for jumper-find-dir but I am getting this error message:

jumper-find-dir:zle:7: widgets can only be called when ZLE is active
homerours commented 4 months ago

Hi, yes I am getting it as well. I believe that jumper-find-dir may not be what you would like to use here. Would something like

alias zi='cd $(__jumper_fdir)'

suits your needs ?

jemorriso commented 4 months ago

Works like a charm, thanks. I've now got

alias zi='cd $(__jumper_fdir)'
alias zfi='$EDITOR $(__jumper_ffile)'

Loving the program so far!

homerours commented 4 months ago

Nice ! However one should maybe handle the case where you cancel the search with ctrl-c (in that case $EDITOR will open an empty file, or you would cd back home). One should probably rather use a function for that, e.g.

zi() {
    new_path=$(__jumper_fdir)
    if [[ -n $new_path ]]; then
        cd "$new_path"
    fi
}

zfi() {
    file=$(__jumper_ffile)
    if [[ -n $file ]]; then
        $EDITOR "$file"
    fi
}

This is quite useful to have, I added it by default: https://github.com/homerours/jumper/commit/8a9e6e07d2e437dcc77e59d0d0c4cef39f7e9325 Thanks for the suggestion :)

jemorriso commented 4 months ago

beautiful, thanks!