LoginSignup
1
1

More than 5 years have passed since last update.

コマンドラインでディレクトリを mark & jump

Posted at

良く移動するディレクトリをマークしてジャンプするためのtips。.bashrcに追加して使用
autojumpzみたいな感じのやつですかね。使った事無いですが。

.bashrc
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
}

マーキングしたいディレクトリで

mark

名前付けたい時は

mark huge

マークした一覧表示は

marks

マークしたディレクトリに移動は

jump huge

マークの削除は

unmark huge

元ソースはこちらとかとか
Quickly navigate your filesystem from the command-line
https://news.ycombinator.com/item?id=6229001
https://github.com/robbyrussell/oh-my-zsh/pull/2045

自分が使いやすく書き直したりしてるのでそれぞれの好みで変更してくだされ。

bash_completionを使っている人は$HOME/.bash_completionに以下を記述すればコマンドの補完が可能

.bash_completion
function _completemarks() {
    local keys word

    word=${COMP_WORDS[COMP_CWORD]}
    keys=$(echo $MARKPATH/* | for f in $(xargs) ; do basename $f ; done | xargs)

    if [ ${#keys[*]} -gt 0 ]; then
        COMPREPLY=($(compgen -W "${keys[@]}" $word))
    fi

    return 0
}

complete -F _completemarks jump
complete -F _completemarks unmark
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1