To have completion with bash you can use this: function _jump { local cur=${COMP_WORDS[COMP_CWORD]} local marks=$(find $MARKPATH -type l -printf "%f\n") COMPREPLY=($(compgen -W '${marks[@]}' -- "$cur")) return 0 } complete -o default -o nospace -F _jump jump Bash completion really needs better docs :-|
Hmmm, this doesn't seem to work in `zsh`. Typing `jump ` suggests everything in the current directory (folders and files). Does anyone here know offhand how autocompletion in `zsh` works?
Quickly navigate your filesystem from the command line
101–110 of 148 posts
Re: Quickly navigate your filesystem from the command line
#102For Windows users I have a closely related shameless plug: cdhere navigates your cmd.exe to wherever the current topmost Explorer window is pointed at. It's not the same as the OP's trick, of course, but since you're voluntarily using Windows, I'm going to assume you "live" on the command line less than the average UNIX user, and more on GUI tools such as good old Explorer. https://github.com/eteeselink/cdhere
Re: Quickly navigate your filesystem from the command line
#103Earlier quoted context omitted.
I used to have a really hacky AppleScript to do the same thing in OS X. The crappy part was that launching the whole AppleScript runtime was really slow, but that was the only API I could find with getting that information from the Finder.
You can also drag any file or folder onto your terminal, which will paste the absolute filepath at your cursor point.
Re: Quickly navigate your filesystem from the command line
#104You can also use ranger [1] to change directories, especially if you want to explore the directory tree quickly when you don't know exactly where to jump to. Install it and add the following to ~/.bashrc: function ranger-cd { tempfile='/tmp/chosendir' /usr/bin/ranger --choosedir="$tempfile" "${@:-$(pwd)}" test -f "$tempfile" && if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then cd -- "$(cat "$tempfile")" fi r…
Re: Quickly navigate your filesystem from the command line
#105 set MARKPATH $HOME/.marks
function jump
cd $MARKPATH/$argv; or echo "No such mark: $argv"
end
function mark
mkdir -p $MARKPATH; and ln -s (pwd) $MARKPATH/$argv
end
function unmark
rm -i $MARKPATH/$argv
end
function marks
ls -l $MARKPATH | cut -d' ' -f12-; and echo
endRe: Quickly navigate your filesystem from the command line
#106Jeroen
Re: Quickly navigate your filesystem from the command line
#107Re: Quickly navigate your filesystem from the command line
#108 alias .=cd
In /bin/sh "." sources a script. While this can be common in a script, one rarely does this interactively so I usurped . for the most common operation! alias ,=pushd
alias ,,=popd
alias ,.=dirs
Think of cd as a goto, pushd as a call, popd as a return and dirs as a stack trace! ..() { cd ../$* }
cdpath=(. .. ~/src ~)
Use of cdpath can be confusing so it is best to show part of $PWD in the prompt: PS1="%* %5. %h%(#.#.:) "
This ends the prompt with a # if you are running as superuser.These aliases/functions are enabled in .zshrc (only if run interactively -- that is, they are included below the following test):
if [[ ! -o interactive ]] ; then return; fi
The "benefit" of Jeroen's mark/unmark is that these paths persist (and can be used from any window running a shell. I have not found much need for that + I can have different $dirs in different windows. Also, given that my shell windows (under screen) persist for a very long time, I don't need symlink's persistence!Alternatively I define "." to be a function that does arg specific operation (cd if a dir, acroread if .pdf, vi if text etc.).
Re: Quickly navigate your filesystem from the command line
#109You might want to check out z: https://github.com/rupa/z
https://github.com/clvv/fasd I used to use z, but I've since switched to fasd. It's much like z, but also so much better. In addition to being able to do "z " you can do "f ". So, for example, if I've got a rails project I've worked on a lot recently I know its config.ru is high on frecency, so I'll just do "vim `f config`" to edit that file. If I want a file that's not so recent I can always do "vim `f -i config`" t…