Skip to content

Instantly share code, notes, and snippets.

@kashewnuts
Last active June 30, 2022 14:45
Show Gist options
  • Save kashewnuts/e4b3cd282a5a8ff853a22a904ee68783 to your computer and use it in GitHub Desktop.
Save kashewnuts/e4b3cd282a5a8ff853a22a904ee68783 to your computer and use it in GitHub Desktop.
peco & ghq でいい感じにした bashrc (関連部分だけ抜粋)
# bash history
export HISTSIZE=10000
export HISTCONTROL=ignoreboth # ignorespace+ignoredups = ignoreboth
export HISTIGNORE="ls:fg*:history*"
# peco
function peco-repo() {
local selected_file=$(ghq list --full-path | peco --query "$LBUFFER")
if [ -n "$selected_file" ]; then
if [ -t 1 ]; then
echo ${selected_file}
cd ${selected_file}
fi
fi
}
bind -x '"\C-]": peco-repo'
function peco-cd() {
if [[ -z "$1" ]]; then
local dir="$( find . -maxdepth 3 -type d | sed -e 's;\./;;' | peco )"
if [ ! -z "$dir" ] ; then
cd "$dir"
fi
else
cd "$1"
fi
}
alias pcd="peco-cd"
peco-history() {
local NUM=$(history | wc -l)
local FIRST=$((-1*(NUM-1)))
if [ $FIRST -eq 0 ] ; then
# Remove the last entry, "peco-history"
history -d $((HISTCMD-1))
echo "No history" >&2
return
fi
local CMD=$(fc -l $FIRST | sort -k 2 -k 1nr | uniq -f 1 | sort -nr | sed -E 's/^[0-9]+[[:blank:]]+//' | peco | head -n 1)
if [ -n "$CMD" ] ; then
# Replace the last entry, "peco-history", with $CMD
history -s $CMD
if type osascript > /dev/null 2>&1 ; then
# Send UP keystroke to console
(osascript -e 'tell application "System Events" to keystroke (ASCII character 30)' &)
fi
# Uncomment below to execute it here directly
# echo $CMD >&2
# eval $CMD
else
# Remove the last entry, "peco-history"
history -d $((HISTCMD-1))
fi
}
bind -x '"\C-r": peco-history'
[ghq]
root = ~/projects # 場所は任意
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment