Skip to content

Commit

Permalink
remove old persistent session code, various linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nikvdp committed Dec 29, 2022
1 parent d20c78a commit 9359cf4
Showing 1 changed file with 5 additions and 37 deletions.
42 changes: 5 additions & 37 deletions pbproxy
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,9 @@
# this is used to emulate a clipboard on machines where xsel and/or
# pbcopy/pbpaste aren't present (eg a headless linux box with no X servre)
PBPROXY_TEMPFILE="/tmp/pboard"
PBPROXY_SESSION_TIMEOUT="$((24 * 60 * 60))"

main() {
case "$1" in
--start-session | -s)
remote_host="$2"
# write session file
cat >~/.pbproxy <<EOF
pbproxy_last_run_time="$(date +%s)"
remote_host="$remote_host"
EOF
echo >&2 "Started remote pbproxy session for host '$remote_host'"
return
;;
--end-session | -S)
rm ~/.pbproxy
echo >&2 "Ended remote pbproxy session"
return
;;
--help | -h)
show-usage
return 0
Expand All @@ -30,18 +14,6 @@ EOF

local remote_host="$1"

# load remote host from file if there's a valid session
if [[ -f ~/.pbproxy ]] && [[ -z "$remote_host" ]]; then
remote_host="$(
# pbproxy should set "$pbproxy_last_run_time" and "$remote_host"
source ~/.pbproxy
# if session was set w/in last day
if [[ $(($(($(date +%s))) - pbproxy_last_run_time)) -lt "$PBPROXY_SESSION_TIMEOUT" ]]; then
echo "$remote_host"
fi
)"
fi

if [[ -n "$remote_host" ]]; then
case "$SCRIPT_NAME" in
pbcopy | *copy*)
Expand Down Expand Up @@ -71,6 +43,8 @@ EOF
;;
esac
else
# Fall back to storing clipboard contents in a tempfile if xsel is
# not available
case "$SCRIPT_NAME" in
pbcopy | *copy*)
exec cat >"$PBPROXY_TEMPFILE"
Expand All @@ -88,7 +62,7 @@ EOF
show-usage() {
cat <<EOF
$(basename $0)
$(basename "$0")
pbcopy/pbpaste and xsel wrapper with remote session support.
Expand All @@ -102,22 +76,17 @@ Copy to another machine's clipboard:
echo hi | pbcopy <hostname>
Usage:
-s, --start-session <hostname>
-S, --end-session <hostname>
EOF
return 0
}

quiet() {
$@ &>/dev/null
"$@" &>/dev/null
}

abspath() {
local dir=
local file=
local res=
if quiet pushd "$1"; then
pwd
quiet popd
Expand All @@ -130,8 +99,7 @@ abspath() {
fi
}

SCRIPT_NAME="$(basename $0)"
SCRIPT_DIR="$(abspath $(dirname $0))"
SCRIPT_NAME="$(basename "$0")"
CUR_PLATFORM="$(uname)"

main "$@"

0 comments on commit 9359cf4

Please sign in to comment.