Last active
August 29, 2015 14:06
-
-
Save k14i/f3dcb194cd9d0619fcf4 to your computer and use it in GitHub Desktop.
tmux-pbcopy
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
#!/bin/bash | |
if test x`uname -s` != x'Darwin'; then | |
exit 0 | |
fi | |
if test `which reattach-to-user-namespace > /dev/null; echo $?` -ne 0; then | |
echo 'Error: reattach-to-user-namespace does not found.' | |
if test `which brew > /dev/null; echo $?` -eq 0; then | |
echo 'Info: Install reattach-to-user-namespace with homebrew.' | |
brew install reattach-to-user-namespace | |
if test $? -eq 0; then | |
echo 'Info: reattach-to-user-namespace installed. Please copy it again.' | |
exit 0 | |
else | |
echo 'Error: reattach-to-user-namespace installation failed.' | |
exit 1 | |
fi | |
else | |
echo 'Error: There is no homebrew so cannot install reattach-to-user-namespace.' | |
exit 1 | |
fi | |
fi | |
buf="$HOME/.tmux-pbcopy_buffer" | |
char_count=20 | |
clipboard_history_dir="$HOME/.tmux-pbcopy_history/`date +%Y`/`date +%m`/`date +%d`" | |
clipboard_history="$clipboard_history_dir/`date +%Y%m%d_%H%M%S`.txt" | |
echo -n '' > $buf | |
tmux save-buffer $buf | |
msg_bytes=`wc -c $buf | awk '{print $1}'` | |
if test $msg_bytes -eq 0; then | |
echo 'Info: Nothing was copied.' | |
exit 0 | |
fi | |
cat $buf | pbcopy | |
if test ! -d $clipboard_history_dir; then | |
mkdir -p -m 700 $clipboard_history_dir | |
fi | |
msg_head=`head -c $char_count $buf` | |
msg_tail=`tail -c $char_count $buf` | |
tmux display-message "Copy $msg_bytes bytes: From:[$msg_head ...], To:[... $msg_tail]" | |
pbpaste | tee -a $clipboard_history > /dev/null | |
chmod 600 $clipboard_history | |
echo -n '' > $buf | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment