2
1

More than 3 years have passed since last update.

aliasを使ってコマンドを省略する

Last updated at Posted at 2020-01-14

可能な限り省略コマンドを書いてコードを打つ時間を減らしたいという思いがあったため、
aliasを組んで省略コマンドを記載しています。

aliasを組むメリット

  1. 打つのが早くなることによる開発スピードの向上・ストレスの削減
  2. よく使うコマンドを打つ際に、思い出すという労力を使わなくて良くなる。

aliasを組むデメリット

  1. 自分で組んだaliasコマンドを覚えないと利便性がない
  2. 省略コマンド元のコマンドを忘れることがある

大筋のやり方については下記を参考にしています。
https://qiita.com/ma_me/items/f76295f3da9579043bbc

viで記載

vi ~/.bash_profile

下記の省略コマンド群をコピペし、再起動をかけたのち(source ~/.bash_profile)は

vb

でも.bash_profileの変更をすることが可能です、

省略コマンドを記載

alias c='cd ..'
alias ci='composer install'
alias cl='cd laradock'
alias cpl='composer create-project laravel/laravel --prefer-dist'
alias cpu='composer update'
alias cv='composer -v'
alias d='docker'
alias dc='docker-compose'
alias dcbn='docker-compose build --no-cache'
alias dcd='docker-compose down'
alias dcl='docker-compose up -d mysql nginx php-fpm workspace'
alias dcls='docker-compose up -d mysql nginx php-fpm workspace selenium'
alias dem='docker exec -it laradock_mysql_1 bash'
alias dew='docker exec -it laradock_workspace_1 bash'
alias dp='docker ps'
alias dr='docker rm $(docker ps -q -a)'
alias ds='docker stop $(docker ps -q)'
alias g='git'
alias ga='git add'
alias gaa='git add .'
alias gaaa='git add -A'
alias gb='git branch'
alias gba='git branch -a'
alias gbd='git branch -d'
alias gbdd='git branch -D'
alias gbm='git branch -m'
alias gc='git commit'
alias gcam='git commit --amend -m'
alias gcl='git clone https://github.com/LaraDock/laradock.git'
alias gcm='git commit -m'
alias gco='git checkout'
alias gco.='git checkout .'
alias gcob='git checkout -b'
alias gcom='git checkout master'
alias gd='git diff'
alias gda='git diff HEAD'
alias gi='git init'
alias gl='git log'
alias gld='git log --pretty=format:"%h %ad %s" --date=short --all'
alias glg='git log --graph --oneline --decorate --all'
alias gm='git merge --no-ff'
alias gp='git pull'
alias gr='git remote -v'
alias gra='git remote add'
alias grh='git reset --hard HEAD^'
alias gs='git status'
alias gss='git status -s'
alias gst='git stash'
alias gstd='git stash drop'
alias gstl='git stash list'
alias gstp='git stash pop'
alias gsub='git submodule'
alias gsubu='git submodule update'
alias h='history'
alias hg='history | grep'
alias la='ls -al'
alias ni='npm install'
alias nrd='npm run dev'
alias nu='npm update'
alias nv='npm -v'
alias sb='source ~/.bash_profile'
alias vb='vi ~/.bash_profile'

説明部分

Version管理系(npm、composer)・環境構築系(Docker)・Gitでよく使うコマンド・Linuxコマンドをまとめたものになります。

一部dcl(docker-compose up -d mysql nginx php-fpm workspace)のように、(「l」は「laradock」の「l」)別の命名をしているものもありますが、大体のコマンドの命名規則は頭の文字を取っているものが多いため、想起しやすいかと思われます。

既存のサイトで載っているものより、Dockerコマンドやgrepなどよく使うLinuxコマンドもaliasに追加しているため、よりコンテンポラリーになったかと思います。

再起動(これによって変更が反映される)

source ~/.bash_profile

上記省略コマンド群をコピペしていただければ、下記コマンドでも反映されます。

sb

反映されているか確認

alias

悩んでいる点

  1. workspace配下のaliasがきかない
  2. php artisan migrate:refreshをpamrとか省略できない。

改善点の変遷

Ver3

npmもローカルに入れたので、npm系のコマンドも省略してみました。

alias ni='npm install'
alias nrd='npm run dev'
alias nu='npm update'
alias nv='npm -v'

Ver4

省略コマンドを打つのすら面倒くさくなったため、省略コマンドをかくコマンドすらも省略しました。

alias sb='source ~/.bash_profile'
alias vb='vi ~/.bash_profile'

git remote系追加

alias gr='git remote -v'
alias gra='git remote add’

直前のCommitを取り消す

alias grh='git reset --hard HEAD^'

Laradock導入コマンド

alias gcl='git clone https://github.com/LaraDock/laradock.git'

history系

alias h='history'
alias hg='history | grep'

Ver5

ブランチ名の変更。

alias gbm='git branch -m'

git submodule系のコマンド

alias gsub='git submodule'
alias gsubu='git submodule update'

git commit系

alias gcam='git commit --amend -m'

読んでいただき誠にありがとうございました。よく使うコマンドは適宜追記していきたいと考えています。また、よく使うコマンドでこちらに記載のないものは、随時追加していきたいためこちらまで教えていただければ幸いです。

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