Help us understand the problem. What is going on with this article?

mkdirしたディレクトリにそのまま移動するfunctionをfishで実装した。

More than 1 year has passed since last update.

mkdirして追加したディレクトリに、そのまま移動するためのコマンドをfish shellのfunctionとして実装してみた。

function mkcd
  if test (count $argv) -eq 0
    echo "Pass dir name"
    return 1
  end

  set dirname $argv[1]
  mkdir -p $dirname
  eval "cd" $dirname
end

pオプションでmkdirを実行するので、複数階層を一度に作って遷移することも可能。
evalを使ってcdしているが、これをしないとコマンド終了時に元のプロセスに戻ったタイミングで実行していたパスになってしまう。この辺りはbashと同じ。

使い方は以下の通り。

~> mkcd test 
~/test> 
~/test> mkcd t1/t2
~/t/t/t2> 
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした