やる気がストロングZERO

やる気のストロングスタイル

zshに戻した

fish使ってたがzshに戻した。

これに影響受けた:

ひさしぶりにzshに戻りました - ちなみに

fish便利だったが、bashと互換性がないのでみんなが使えるshellスクリプトが動かなかったりして、開発メンバーと自分だけが足並み揃わないのがストレスだった。

fishを使いこなしてるわけでもなく、数えるくらいの機能しか使ってないので、ちょっと頑張ってzsh設定するか、、という感じでzshに行った設定をメモっておく。

ちなみにwslのubuntuzsh設定を行った。

やりたかったこと

一応これらは実行できるようになった。

手順

homebrew入れる。
インストール後に表示される指示通りにbuild-essentialとかgccとか入れた

==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
    echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> /home/mix/.profile
    eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
- Install Homebrew's dependencies if you have sudo access:
    sudo apt-get install build-essential
  For more information, see:
    https://docs.brew.sh/Homebrew-on-Linux
- We recommend that you install GCC:
    brew install gcc
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

zshインストール。

brew install zsh

デフォルトシェル変更

# /etc/shellsに追記しとかないとbrewで入れたzshはchshで許可されない
command -v zsh | sudo tee -a /etc/shells
sudo chsh -s "$(command -v zsh)" "${USER}"

.zshrc にbrewの設定追記する

eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"

zim入れる
https://zimfw.sh/docs/install/

curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh

ghqインストール

brew install ghq

fzfインストール

brew install fzf

fzfのキーバインドとか、補完設定。

# これを実行
$(brew --prefix)/opt/fzf/install

その他設定を.zshrcに追記

# 履歴
# メモリに保存される履歴の件数
export HISTSIZE=1000
# 履歴ファイルに保存される履歴の件数
export SAVEHIST=100000
# 重複を記録しない
setopt hist_ignore_dups
# 開始と終了を記録
setopt EXTENDED_HISTORY

setopt no_beep

## cdrを有効にして設定する
autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
add-zsh-hook chpwd chpwd_recent_dirs
zstyle ':completion:*:*:cdr:*:*' menu selection
zstyle ':chpwd:*' recent-dirs-max 100
zstyle ':chpwd:*' recent-dirs-default true
zstyle ':chpwd:*' recent-dirs-insert true
zstyle ':chpwd:*' recent-dirs-file "$HOME"/.chpwd-recent-dirs
## AUTO_CDの対象に ~ と上位ディレクトリを加える
cdpath=(~ ..)

# repositoryルートに戻る
function u() {
  cd ./"$(git rev-parse --show-cdup)"
  if [ $# = 1 ]; then
    cd "$1"
  fi
}

# ghq
function ghq-fzf() {
  local target_dir=$(ghq list -p | fzf --query="$LBUFFER")

  if [ -n "$target_dir" ]; then
    BUFFER="cd ${target_dir}"
    zle accept-line
  fi

  zle reset-prompt
}
zle -N ghq-fzf
bindkey "^[g" ghq-fzf

# git branch
function git-fzf() {
  local target_branch=$(git branch -a | fzf | awk '$1=="*"{print $2}$1!="*"{print $1}')

  if [ -n "$target_branch" ]; then
    BUFFER="git checkout ${target_branch}"
    zle accept-line
  fi

  zle reset-prompt
}
zle -N git-fzf
bindkey "^[b" git-fzf

# cdr
function cdr-fzf() {
  local target_dir=$(cdr -l | fzf | awk '{print $2}')

  if [ -n "$target_dir" ]; then
    BUFFER="cd ${target_dir}"
    zle accept-line
  fi

  zle reset-prompt
}
zle -N cdr-fzf
bindkey "^[c" cdr-fzf


### エイリアス
alias ls='ls -F' la='ls -a' ll='ls -la'