Created
October 23, 2012 01:07
-
-
Save yonchu/3936059 to your computer and use it in GitHub Desktop.
直前に実行したコマンドをクリップボードへ(zsh on Mac Only)
This file contains 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
# 直前のコマンドをクリップボードへ | |
# 第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