add smart_copy, refactor remote clipboard names.

This commit is contained in:
Ivan Malison 2014-04-13 23:19:14 -07:00
parent c42793b3c5
commit e84668c75a
3 changed files with 37 additions and 6 deletions

View File

@ -1,6 +1,5 @@
alias emacs="emacsclient -t" alias emacs="emacsclient -t"
alias tmux="tmux -2" alias tmux="tmux -2"
alias remote_os_copy='linux_nc_paste_to_remote_clipboard'
alias tmux_cb_to_remote_cb='tmux saveb - | linux_nc_paste_to_remote_clipboard' alias tmux_cb_to_remote_cb='tmux saveb - | linux_nc_paste_to_remote_clipboard'
alias timestamp='date +%s' alias timestamp='date +%s'
alias go2dotfiles='cd $(dirname `readlink -f ~/.zshrc | xargs dirname`)' alias go2dotfiles='cd $(dirname `readlink -f ~/.zshrc | xargs dirname`)'

View File

@ -87,9 +87,23 @@ function shell_stats() {
} }
function is_ssh() { function is_ssh() {
p=${1:-$PPID} test $SSH_CLIENT
read pid name ppid < <(ps -o pid= -o comm= -o ppid= -p $p) }
[[ "$name" =~ sshd ]] && { echo "Is SSH : $pid $name"; return 0; }
[ "$ppid" -le 1 ] && { echo "Adam is $pid $name"; return 1; } function is_osx() {
is_ssh $ppid case `uname` in
'Darwin')
return 0
;;
*)
return 1;
;;
esac
}
function clipboard() {
if is_osx;
then
pbcopy
fi
} }

View File

@ -18,3 +18,21 @@ function linux_nc_paste_to_remote_clipboard() {
function osx_nc_paste_to_remote_clipboard() { function osx_nc_paste_to_remote_clipboard() {
nc localhost ${1-$REMOTE_CLIPBOARD_PORT} -D nc localhost ${1-$REMOTE_CLIPBOARD_PORT} -D
} }
function remote_os_copy() {
if is_osx;
then
osx_nc_paste_to_remote_clipboard
else
linux_nc_paste_to_remote_clipboard
fi
}
function smart_copy() {
if is_ssh;
then
remote_os_copy
else
clipboard
fi
}