Skip to content

Instantly share code, notes, and snippets.

@yonchu
Created October 23, 2012 01:07
Show Gist options
  • Save yonchu/3936059 to your computer and use it in GitHub Desktop.
Save yonchu/3936059 to your computer and use it in GitHub Desktop.
直前に実行したコマンドをクリップボードへ(zsh on Mac Only)
# 直前のコマンドをクリップボードへ
# 第1引数:何個前のコマンドか, 未指定時は1個前のコマンドをコピー
#
# Note: .zshrc に設定して使用(エイリアス: pbcc)
#
copy_prev_cmd_to_clipboard () {
if [ -n "$1" ] && ! expr "$1" : '[0-9]*' > /dev/null ; then
echo "error: non-numeric argument" 1>&2
return 1
fi
local num=${1:-1};
num=$((num + 1))
tail "-$num" "$HISTFILE" | perl -e '<> =~ m/;(.+)/; print $1;' | pbcopy
}
alias pbcc='copy_prev_cmd_to_clipboard'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment