3 ms·
I 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 ex
by microcolonel 13y ago
I 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 -d' ' -f9- | sed 's/ -/\t-/g' && echo
}
_completemarks() {
local curw=${COMP_WORDS[COMP_CWORD]}
local wordlist=$(find $MARKPATH -type l -printf "%f\n")
COMPREPLY=($(compgen -W '${wordlist[@]}' -- "$curw"))
return 0
}
complete -F _completemarks jump unmark
- DigitalJack 13y agoI recommend avoiding -f on rm if you can. Make one mistake and it can be painful. In this case think removing the -i from the unmark function will accomplish what you want. I made something to the OP's system for the same reason of disdain for super deep trees at work. I'll make a gist and edit this post with it in a few minutes. Edit: https://gist.github.com/desertmonad/6258429 https://gist.github.com/desertmonad/6258429 I like the OP's idea of using symbolic links. That makes it more generally useful (i.e. a gui app can use those simple paths too). I may switch over to that.
- likeclockwork 13y agoWhy not use unlink?
- DigitalJack 13y agoWhat's the advantage?
- coherentpony 13y agoThe purpose of the -i flag is to prompt the user before deleting. Mixing the -i and -f flags is a little moot. Try removing the -i option to obtain what you want.
- microcolonel 13y agoDidn't catch that, it was a quick hack of an edit, thanks.
- Daniel_Newby 13y agoThe variable expansions really ought to be quoted, like this: function unmark { rm -if "$MARKPATH/$1" } Otherwise you are asking for much sadness.
- mcoliver 13y agonice additions. For OSX I had to modify the local wordlist part of the auto complete function to read: local wordlist=$(ls $MARKPATH)
- oscargodson 13y agofind: blah<tab>-printf: unknown primary or operator Any idea why this is happening? I'm on OS X.
- mirkob 13y agoNice job! I had to modify _completemarks() function though to work on OSX. _completemarks() { local curw=${COMP_WORDS[COMP_CWORD]} local wordlist=$(find $MARKPATH -type l -exec basename {} \;) COMPREPLY=($(compgen -W '${wordlist[@]}' -- "$curw")) return 0 }