romanohu

pet

シンプルなコマンドラインスニペット管理ツール


コマンドを登録する
<>で囲んだ部分は呼び出すときに入力できる

pet new
# タグ付きにする
pet new -t

コマンドを編集する

pet edit

コマンドを検索して実行

pet search

tips1
以下を.zshrcに貼り付けるとCtrl+sでpet searchを呼び出せる(zsh)

function pet-select() {
  BUFFER=$(pet search --query "$LBUFFER")
  CURSOR=$#BUFFER
  zle redisplay
}
zle -N pet-select
stty -ixon
bindkey '^s' pet-select

function pet-select() {
  BUFFER=$(pet search --query "$LBUFFER")
  CURSOR=$#BUFFER
  zle redisplay
}
zle -N pet-select
stty -ixon
bindkey '^s' pet-select

function _pet_move_cursor_to_next_parameter() {
    match="$(echo "$BUFFER" | perl -nle 'print $& if /<.*?>/')"
    if [ -n "$match" ]; then
      default="$(echo "$match" | perl -nle 'print $& if /(?<==).*(?=>)/')"
      match_len=${#match}
      default_len=${#default}
      parameter_offset=${#BUFFER%%$match*}

      CURSOR="$((${parameter_offset} + ${default_len}))"
      BUFFER="${BUFFER[1,$parameter_offset]}${default}${BUFFER[$parameter_offset+$match_len+1,-1]}"
    fi        
}
zle -N _pet_move_cursor_to_next_parameter
bindkey '^n' _pet_move_cursor_to_next_parameter 

tips2
Gistを使って端末間でコマンドを共有できる

pet configure
# [Gist]のaccess_tokenに https://gitlab.com/-/profile/personal_access_tokensで取得したトークンを入れる
pet sync