LoginSignup
24
24

More than 5 years have passed since last update.

ファイル/ディレクトリを検索して、peco って cd するやつ 2

Last updated at Posted at 2014-07-06

ファイルを検索して、peco って cd するやつ - Qiita
mdfind でなくても、find でも -maxdepth を指定すれば性能が出ることがわかったので、改良版を作りました。

peco-find-cd() {
  local FILENAME="$1"
  local MAXDEPTH="${2:-3}"
  local BASE_DIR="${3:-`pwd`}"

  if [ -z "$FILENAME" ] ; then
    echo "Usage: peco-find-cd <FILENAME> [<MAXDEPTH> [<BASE_DIR>]]" >&2
    return 1
  fi

  local DIR=$(find ${BASE_DIR} -maxdepth ${MAXDEPTH} -name ${FILENAME} | peco | head -n 1)

  if [ -n "$DIR" ] ; then
    DIR=${DIR%/*}
    echo "pushd \"$DIR\""
    pushd "$DIR"
  fi
}

peco-git-cd() {
  peco-find-cd ".git" "$@"
}

peco-docker-cd() {
  peco-find-cd "Dockerfile" "$@"
}

peco-vagrant-cd() {
  peco-find-cd "Vagrantfile" "$@"
}

peco-go-cd() {
  peco-find-cd ".git" 5 "$GOPATH"
}

これで、最後の例のように go のソースに簡単に行けるようになりました。

24
24
5

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
24
24