Skip to content

Instantly share code, notes, and snippets.

@jon-uw
Last active December 21, 2015 22:19
Show Gist options
  • Select an option

  • Save jon-uw/6374730 to your computer and use it in GitHub Desktop.

Select an option

Save jon-uw/6374730 to your computer and use it in GitHub Desktop.
linux directory mark utils to change dir fast. copy from: http://www.ccvita.com/520.html
#!/bin/bash
# mark dir
# add this line to ~/.bashrc:
# if [ -f cd_mark ]; then ./cd_mark; fi
# usage: func $mark
# mls: list all the mark
# mcd: cd marked dir
# mark: add new mark
# unmark: delete mark
# dir mark
export MARK_DIR=$HOME/.marks
export DEFAULT_MARK=tango
function mcd {
local m=$1
if [ "$m" = "" ]; then m=$DEFAULT_MARK; fi
cd -P "$MARK_DIR/$m" 2>/dev/null || echo "No such mark: $m"
}
function mark {
mkdir -p $MARK_DIR
local m=$1
if [ "$m" = "" ]; then m=$DEFAULT_MARK; fi
rm -f $MARK_DIR/$m
ln -s `pwd` $MARK_DIR/$m
}
function unmark {
local m=$1
if [ "$m" = "" ]; then m=$DEFAULT_MARK; fi
rm -i "$MARK_DIR/$m"
}
function mls {
# sed to replace multiple spaces to one
ls -l "$MARK_DIR" | grep ^l | sed 's/\s\s*/ /g' | cut -d ' ' -f 9-
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment