4 ms·
I 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 $MARKPA
by modernerd 13y ago
I 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
}
- guygurari 13y agoHere 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}' }
- 0x09 13y agoIf you are on a system with BSD stat like OS X you can get the same with function marks { (cd $MARKPATH && stat -f"%-10SN%SY" *) } Even better with column (t="$(printf "\t")"; cd $MARKPATH && stat -f"%N$t%SY" * | column -ts"$t")
- flyswatter 13y agoOne more fix... if you have group names with spaces this will throw the field number off and you'll see the modification time preceding the mark name. 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}'
- beders 13y agoAnd 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
- cachvico 13y agoShouldn't this be complete -o default -o nospace -F _jump jump unmark and then it simply replaces the existing _completemarks(), instead of needing both?
- svantana 13y agoThanks! Also, since alot of OSX paths contain whitespaces, I had to modify the mark function like so: function mark { mkdir -p $MARKPATH; ln -s "$(pwd)" $MARKPATH/$1 } Disclaimer: I'm not very good at bash, perhaps there is a nicer solution to this problem?
- sambeau 13y agoI went with: function marks { ls -l $MARKPATH | sed -E 's/ +/ /g' | cut -d' ' -f9- | sed -E 's/ -/ -/g' && echo } where the "\t" (looks like a bunch of spaces in the second sed statement) was typed in using [Ctrl] + [V] and then [Tab].