Last active
August 18, 2023 00:30
-
-
Save patorash/6b78407495a7bf55e0e2ed37d40933cf to your computer and use it in GitHub Desktop.
公開用.zshrc。rbenv, nodenv, goenv, pyenv, zplug, peco, ghqをインストールしてあること。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export PATH="~/bin:$PATH" | |
export GOENV_ROOT="$HOME/.goenv" | |
export PATH="$GOENV_ROOT/bin:$PATH" | |
eval "$(goenv init -)" | |
export RBENV_ROOT="$HOME/.rbenv" | |
export PATH="$RBENV_ROOT/bin:$PATH" | |
eval "$(rbenv init -)" | |
export NODENV_ROOT="$HOME/.nodenv" | |
export PATH="$NODENV_ROOT/bin:$PATH" | |
eval "$(nodenv init -)" | |
export PYENV_ROOT="$HOME/.pyenv" | |
export PATH="$PYENV_ROOT/bin:$PATH" | |
eval "$(pyenv init -)" | |
# Macの場合 | |
# export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix [email protected])" | |
export ZPLUG_HOME=$HOME/.zplug | |
source $ZPLUG_HOME/init.zsh | |
zplug "modules/history", from:prezto | |
zplug "modules/directory", from:prezto | |
zplug "plugins/git", from:oh-my-zsh | |
zplug "plugins/docker-compose", from:oh-my-zsh | |
zplug "plugins/bundler", from:oh-my-zsh | |
zplug "plugins/ssh-agent", from:oh-my-zsh | |
# SSH Agent | |
zstyle :omz:plugins:ssh-agent agent-forwarding yes | |
zstyle :omz:plugins:ssh-agent identities id_ed25519 | |
# コード補完 | |
zplug "zsh-users/zsh-autosuggestions" | |
zplug "zsh-users/zsh-completions" | |
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=5' | |
# Load theme file | |
zplug 'dracula/zsh', as:theme | |
DRACULA_DISPLAY_TIME=1 | |
DRACULA_DISPLAY_CONTEXT=1 | |
# Lines configured by zsh-newuser-install | |
HISTFILE=~/.histfile | |
HISTSIZE=1000 | |
SAVEHIST=1000 | |
setopt autocd beep extendedglob nomatch notify | |
# bindkey -e | |
# End of lines configured by zsh-newuser-install | |
# The following lines were added by compinstall | |
zstyle :compinstall filename "$HOME/.zshrc" | |
autoload -Uz compinit | |
compinit | |
# End of lines added by compinstall | |
if ! zplug check --verbose; then | |
zplug install | |
fi | |
zplug load --verbose | |
# ctrl + Rで、pecoでhistoryを参照 | |
function peco-select-history() { | |
# historyを番号なし、逆順、最初から表示。 | |
# 順番を保持して重複を削除。 | |
# カーソルの左側の文字列をクエリにしてpecoを起動 | |
# \nを改行に変換 | |
BUFFER="$(history -nr 1 | awk '!a[$0]++' | peco --query "$LBUFFER" | sed 's/\\n/\n/')" | |
CURSOR=$#BUFFER # カーソルを文末に移動 | |
zle -R -c # refresh | |
} | |
zle -N peco-select-history | |
bindkey '^R' peco-select-history | |
# option + sで、pecoでSSH | |
function peco-ssh () { | |
local selected_host=$(awk ' | |
tolower($1)=="host" { | |
for (i=2; i<=NF; i++) { | |
if ($i !~ "[*?]") { | |
print $i | |
} | |
} | |
} | |
' ~/.ssh/config | sort | peco --query "$LBUFFER") | |
if [ -n "$selected_host" ]; then | |
BUFFER="ssh ${selected_host}" | |
zle accept-line | |
fi | |
zle clear-screen | |
} | |
zle -N peco-ssh | |
# Linux | |
# bindkey '^[s' peco-ssh | |
# Mac | |
bindkey 'ß' peco-ssh | |
# option + Gで、pecoでリポジトリ選択 | |
function peco-ghq-cd () { | |
local selected_dir=$(ghq list -p | peco --query "$LBUFFER") | |
if [ -n "$selected_dir" ]; then | |
BUFFER="cd ${selected_dir}" | |
zle accept-line | |
fi | |
zle clear-screen | |
} | |
zle -N peco-ghq-cd | |
# Linux | |
# bindkey '^[g' peco-ghq-cd | |
# Mac | |
bindkey '©' peco-ghq-cd | |
# pecoでgit switch | |
function peco-git-switch () { | |
typeset selected_branch | |
local git_opts=() | |
help() { | |
echo "Usage: peco-git-switch [--remote]" | |
return | |
} | |
case $1 in | |
-h|--help) | |
help | |
return | |
;; | |
-r|--remote) | |
git_opts=( | |
'--remote' | |
'--format=%(refname:lstrip=3)' | |
) | |
selected_branch=$(git branch "${git_opts[@]}" | grep -v "*" | peco --query "$LBUFFER" | tr -d ' ') | |
;; | |
*) | |
selected_branch=$(git branch | grep -v "*" | peco --query "$LBUFFER" | tr -d ' ') | |
esac | |
if [ -n "$selected_branch" ]; then | |
git switch $selected_branch | |
fi | |
} | |
alias select-branch="peco-git-switch" | |
# pecoでマージ済のブランチを削除 | |
function peco-git-delete-branch () { | |
local selected_branch=$(git branch --merged | grep -v "*" | peco --query "$LBUFFER" | tr -d ' ') | |
if [ -n "$selected_branch" ]; then | |
git branch -d $selected_branch | |
fi | |
} | |
alias delete-branch="peco-git-delete-branch" | |
# pecoでkill | |
function peco-kill () { | |
local selected_row=$(ps aux | peco --query "$LBUFFER") | |
if [ -n "$selected_row" ]; then | |
local pid=$(echo $selected_row | awk '{print $2}') | |
echo "kill pid: ${pid}. [${selected_row}]" | |
kill $pid | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment