Quickly navigate your filesystem from the command line
141–148 of 148 posts
Re: Quickly navigate your filesystem from the command line
#142Re: Quickly navigate your filesystem from the command line
#143I had to modify Jeroen's code to get the `marks` shortcut working under Mac OS 10.8: export MARKPATH=$HOME/.marks function jump { cd -P $MARKPATH/$1 2> /dev/null || echo "No such mark: $1" } function mark { mkdir -p $MARKPATH; ln -s $(pwd) $MARKPATH/$1 } function unmark { rm -i $MARKPATH/$1 } function marks { ls -l $MARKPATH | sed 's/ / /g' | cut -d' ' -f9- && echo }
Here is another version of 'marks' for Mac OS that aligns the arrows. It also works when 'ls' is aliased. function marks { \ls -l $MARKPATH | tail -n +2 | sed 's/ / /g' | cut -d' ' -f9- | awk -F ' -> ' '{printf "%-10s -> %s\n", $1, $2}' }
Adding '-n' to the ls command works around this by causing the group id to be printed instead of the group name and all works, i.e.: \ls -ln "$MARKPATH" | tail -n +2 | sed 's/ / /g' | cut -d' ' -f9- | awk -F ' -> ' '{printf "%-10s -> %s\n", $1, $2}'
Re: Quickly navigate your filesystem from the command line
#144Earlier quoted context omitted.
What many people don't seem to know is that the location bar in Explorer (at least on Windows 8) can act as a run dialog, and it supplies the launched program with the current folder as a parameter. So simply hit Ctrl+L and type "cmd" or "powershell" or whatever command from your PATH and hit enter.
Thanks for the tip! Neither Ctrl+L nor Alt+D work for me (Win7 Ultimate, 64bit), but even with clicking manually this is extremely useful for me.
Re: Quickly navigate your filesystem from the command line
#145For 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
You could install cygwin and use the OP technique, though.
Re: Quickly navigate your filesystem from the command line
#146 % cd ~/Dev/W3/m-r-r.github.io
% alias -g :blog="$PWD"
% jekyll build -d /tmp/out/ && cd /tmp/out
% ./index.html
% cd :blog
% pwd
/home/m-r-r/Dev/W3/m-r-r.github.io
% alias -g
:blog='/home/m-r-r/Dev/W3/m-r-r.github.io'
:dev='/home/m-r-r/Dev'
:c='/home/m-r-r/Dev/C'
:python='/home/m-r-r/Dev/Python'
:vim='/home/m-r-r/.vim'
In addition, this method works with any shell command: % pwd
/tmp/out
% make -C :blog publish
% git clone git://git.complang.org/ragel.git `echo :c`/ragel
% vim `echo :vim`/templates/\*.rl
On the other side, the aliases are not saved at exit unless you write a function
to do it: % tail -n 15 ~/.zshrc
function aliases {
(
alias -L -r
alias -L -g
alias -L -s
) | uniq
}
function save-aliases {
aliases > ~/.zsh_aliases
}
if [ -f ~/.zsh_aliases ]; then
. ~/.zsh_aliases
fiRe: Quickly navigate your filesystem from the command line
#147I had to modify Jeroen's code to get the `marks` shortcut working under Mac OS 10.8: export MARKPATH=$HOME/.marks function jump { cd -P $MARKPATH/$1 2> /dev/null || echo "No such mark: $1" } function mark { mkdir -p $MARKPATH; ln -s $(pwd) $MARKPATH/$1 } function unmark { rm -i $MARKPATH/$1 } function marks { ls -l $MARKPATH | sed 's/ / /g' | cut -d' ' -f9- && echo }
And here's a completion code that works for Mac OS: function _jump { local cur=${COMP_WORDS[COMP_CWORD]} local marks=$(find $MARKPATH -type l | awk -F '/' '{print $NF}') COMPREPLY=($(compgen -W '${marks[@]}' -- "$cur")) return 0 } complete -o default -o nospace -F _jump jump
complete -o default -o nospace -F _jump jump unmark
and then it simply replaces the existing _completemarks(), instead of needing both?Re: Quickly navigate your filesystem from the command line
#148I set my version up with a -f on the unmark rm so that I don't need to be prompted to remove it. Also added some basic completion for both jump and unmark export MARKPATH=$HOME/.marks function jump { cd -P $MARKPATH/$1 2>/dev/null || echo "No such mark: $1" } function mark { mkdir -p $MARKPATH; ln -s $(pwd) $MARKPATH/$1 } function unmark { rm -if $MARKPATH/$1 } function marks { ls -l $MARKPATH | sed 's/ / /g' | cut -…
_completemarks() {
local curw=${COMP_WORDS[COMP_CWORD]}
local wordlist=$(find $MARKPATH -type l -exec basename {} \;)
COMPREPLY=($(compgen -W '${wordlist[@]}' -- "$curw"))
return 0
}