wting / autojump

A cd command that learns - easily navigate directories from the command line
Other
16.2k stars 706 forks source link

How to change default key from j to jj? #641

Closed elcolie closed 2 years ago

elcolie commented 2 years ago

I like this tool very much. All of my computers are installed it both osx and GNU/Linux Debian. Currently I am trying to use it with my server the problem is j is been used already.

Question: How to change default key from j to jj in GNU/Linux Debian?

loyalpartner commented 2 years ago

put it in your .bashrc or .zshrc

alias jj='autojump'
elcolie commented 2 years ago

When I use jj. It returns me the path, but my location does not moved!

loyalpartner commented 2 years ago

remove above code and put the below into your bashrc or zshrc

jj() {
        if [[ ${1} == -* ]] && [[ ${1} != "--" ]]
        then
                autojump ${@}
                return
        fi
        setopt localoptions noautonamedirs
        local output="$(autojump ${@})"
        if [[ -d "${output}" ]]
        then
                if [ -t 1 ]
                then
                        echo -e "\\033[31m${output}\\033[0m"
                else
                        echo -e "${output}"
                fi
                cd "${output}"
        else
                echo "autojump: directory '${@}' not found"
                echo "\n${output}\n"
                echo "Try \`autojump --help\` for more information."
                false
        fi
}
elcolie commented 2 years ago

It returns 2 lines. First line is command not found. Second line is the directory to go

$ jj el
bash: setopt: command not found
some/directory/here
loyalpartner commented 2 years ago

It returns 2 lines. First line is command not found. Second line is the directory to go

$ jj el
bash: setopt: command not found
some/directory/here

sorry, i only test it in zsh , i forget bash don't support setopt, you can delete the code

setopt localoptions noautonamedirs

i think it will be ok

elcolie commented 2 years ago

Thank you very much.