13
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

bashで言うところの!$はfishではどうすればよいか

Last updated at Posted at 2017-04-04

mkdirでディレクトリを作成して、そのディレクトリへ移動したいときに

$ mkdir tmp
$ cd !$

とする。
ところが、fishでやると、

> mkdir aa
> cd !$
Expected a variable name after this $.
fish: cd !$
          ^

さて困った。
ちなみに!$はbashで言うところの最後の引数を示す。

こたえ

そのままズバリの質問をしている人がいたのでご紹介。
.config/fish/config.fishに以下を書いて、端末を起動しなおせばよい。

command line - What is the equivalent of bash's !$ and !! in the fish shell? - Super User

適当訳。
fishでは残念ながら!$に該当するものが無い。
メーリングリストにperfect answerがあったんで貼っとくね!

~/.config/fish/config.fish
function bind_bang
    switch (commandline -t)[-1]
        case "!"
            commandline -t $history[1]; commandline -f repaint
        case "*"
            commandline -i !
    end
end

function bind_dollar
    switch (commandline -t)[-1]
        case "!"
            commandline -t ""
            commandline -f history-token-search-backward
        case "*"
            commandline -i '$'
    end
end

function fish_user_key_bindings
    bind ! bind_bang
    bind '$' bind_dollar
end
13
7
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?