zshで履歴拡張のエイリアスを追加するには?

zshで履歴拡張のエイリアスを追加するには?

私はそれが動作したい(extendedglobそして必要ですhistsubstpattern):

alias ri='^(#b)E(?)^E${(l:2::0:)$((match[1]+1))}'

しかし、そうではありません:

$ alias sss='^(#b)E(?)^E${(l:2::0:)$((match[1]+1))}'                                               
$ echo /Users/evar/Downloads/Video/Teenage_Mutant_Ninja_Turtles_2003_S02E01_DVDRip_30NAMA.mkv
/Users/evar/Downloads/Video/Teenage_Mutant_Ninja_Turtles_2003_S02E01_DVDRip_30NAMA.mkv
$ sss                                                                                             
zsh: command not found: Pocket

エイリアスの代わりに関数を使用してもかまいませんが、結果は同じです。

私も試してみてみたexport ss='^(#b)E(?)^E${(l:2::0:)$((match[1]+1))}'$ss失敗したzsh: command not found: ^(#b)E(?)^E${(l:2::0:)$((match[1]+1))}

使用eval '^(#b)E(?)^E${(l:2::0:)$((match[1]+1))}'も失敗しましたzsh: command not found: Pocket

更新:関連する(重複する可能性がある)質問が見つかりました。

zshでbashの `history -p`を置き換えますか?

https://stackoverflow.com/questions/27494753/how-to-get-last-command-run-without-using

https://stackoverflow.com/questions/48696876/using-history-expansion-in-a-bash-alias-or-function

ベストアンサー1

いいえ。履歴拡張は、エイリアスまたはパラメータ拡張の前に発生します。

私は個人的に履歴拡張を嫌うので、最初に無効にします。

E<n>ここでは、履歴拡張エイリアスを使用する代わりに、カーソルの左側の数字を増やすウィジェットを作成することを提案します。

increment-episode() {
  emulate -L zsh
  setopt extendedglob
  LBUFFER=${LBUFFER/(#b)(*E)(<->)/$match[1]${(l:${#match[2]}::0:)$((match[2]+1))}}
}

zle -N increment-episode

bindkey '\e+' increment-episode

その後、+を押すと、Up各段階で何が起こっているのかについての視覚的なフィードバックを得ることができます。しかし、今はより速く、強力なターミナルとラインエディタを持っているので、あまり明確になりました。Alt+

ただし、履歴内の前のコマンドのコードを増加した数で盲目的に評価するには、E次のようにします。

rerun-with-next-episode() {
  emulate -L zsh
  setopt extendedglob
  local new
  new=${${history:0:1}/(#b)E(<->)/E${(l:${#match[1]}::0:)$((match[1]+1))}}

  # display it
  print -ru2 -- $new

  # put it on the history
  print -rs -- $new

  # evaluate it
  eval -- $new
}

おすすめ記事