Project

ghq-cache

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Show frequently used repositories first in ghq list.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
>= 0
~> 10.0

Runtime

~> 0.19
 Project Readme

ghq-cache

Show frequently used repositories first in ghq list.

Installation

brew install motemen/ghq/ghq
gem install ghq-cache

Usage

# Build `ghq list` cache to ~/.ghq-cache
# with ordering of host, user or repositories.
ghq-cache update

# Log your repository access to update ~/.ghq-cache order.
ghq-cache log /Users/k0kubun/src/github.com/k0kubun/ghq-cache

Recommended usage

export GOPATH=$HOME
export GHQ="/usr/local/bin/ghq"
export GIT="/usr/local/bin/git"

function ghq() {
  case $1 in
    get )
      $GHQ $@

      # hook after ghq get
      (ghq-cache update &)
      ;;
    list )
      if [ ! -e ~/.ghq-cache ]; then
        ghq-cache update
      fi

      # use ghq list ordered by ghq-cache
      cat ~/.ghq-cache
      ;;
    * )
      $GHQ $@
      ;;
  esac
}

function git() {
	case $1 in
		init )
			$GIT $@
			(ghq-cache update &)
			;;
		clone )
			$GIT $@
			(ghq-cache update &)
			;;
		* )
			$GIT $@
			;;
	esac
}

function peco-src() {
  local selected_dir=$(ghq list | peco --query "$LBUFFER" --prompt "[ghq list]")
  if [ -n "$selected_dir" ]; then
    full_dir="${GOPATH}/src/${selected_dir}"

    # Log repository access to ghq-cache
    (ghq-cache log $full_dir &)

    BUFFER="cd ${full_dir}"
    zle accept-line
  fi
  zle redisplay
}
zle -N peco-src
stty -ixon
bindkey '^s' peco-src

License

MIT License