2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

みなさんコマンドを打ち間違えることありませんか?

今回はそんな打ち間違えたコマンドを治してくれる魔法のコマンドfuckを紹介したいと思います。

インストール

pipかHomebrewでインストールすることができます。

zsh
brew install thefuck
zsh
pip install thefuck

shellに下記を記述して、読み込みます。
私はzshだったので.zshrcに書いて読み込みました

.zshrc
eval $(thefuck --alias)
zsh
source ~/.zshrc

使ってみる

例えば下のようにコマンドを打ち間違えたとします。

zsh
❯ git poll origin develop
git: 'poll' is not a git command. See 'git --help'.

The most similar command is
        pull

その場合にfuckとコマンドを打つと修正してくれます。

zsh
fuck
zsh
❯ fuck
git pull origin develop [enter/↑/↓/ctrl+c]
From https://github.com/maooz4426/Todolist-go-clean
 * branch            develop    -> FETCH_HEAD
Already up to date

docker composeしたいって時でも

zsh
❯ dockrr compose up
zsh: command not found: dockrr

fuckしたらコマンドを修正することができました。

zsh
❯ fuck
docker compose up [enter/↑/↓/ctrl+c]
[+] Building 18.8s (11/11) FINISHED

使えなかったケース

例えば下のコマンドようにdocker compose upをミスった時は動いてくれませんでした。

zsh
❯ docker compose yp

Usage:  docker compose [OPTIONS] COMMAND

Define and run multi-container applications with Docker

Options:
      --all-resources              Include all resources, even those not used by services
      --ansi string                Control when to print ANSI control characters ("never"|"always"|"auto") (default "auto")
      --compatibility              Run compose in backward compatibility mode
      --dry-run                    Execute command in dry run mode
      --env-file stringArray       Specify an alternate environment file
  -f, --file stringArray           Compose configuration files
      --parallel int               Control max parallelism, -1 for unlimited (default -1)
      --profile stringArray        Specify a profile to enable
      --progress string            Set type of progress output (auto, tty, plain, json, quiet) (default "auto")
      --project-directory string   Specify an alternate working directory
                                   (default: the path of the, first specified, Compose file)
  -p, --project-name string        Project name

Commands:
  attach      Attach local standard input, output, and error streams to a service's running container
  build       Build or rebuild services
  config      Parse, resolve and render compose file in canonical format
  cp          Copy files/folders between a service container and the local filesystem
  create      Creates containers for a service
  down        Stop and remove containers, networks
  events      Receive real time events from containers
  exec        Execute a command in a running container
  images      List images used by the created containers
  kill        Force stop service containers
  logs        View output from containers
  ls          List running compose projects
  pause       Pause services
  port        Print the public port for a port binding
  ps          List containers
  pull        Pull service images
  push        Push service images
  restart     Restart service containers
  rm          Removes stopped service containers
  run         Run a one-off command on a service
  scale       Scale services
  start       Start services
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop services
  top         Display the running processes
  unpause     Unpause services
  up          Create and start containers
  version     Show the Docker Compose version information
  wait        Block until the first service container stops
  watch       Watch build context for service and rebuild/refresh containers when files are updated

Run 'docker compose COMMAND --help' for more information on a command.
unknown docker command: "compose yp"

このコマンドでは無理そうです。

zsh
❯ fuck
docker compose COMMAND --help [enter/↑/↓/ctrl+c]

まとめ

fuckコマンドで簡単にコマンドの修正を行うことができました。

ただ、自動保管できないコマンドもあるようなので、イライラした時にだけ使った方が良さそうですね...

というかqiitaに書くような単語じゃない

2
1
0

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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?