Last active
November 28, 2018 02:00
-
-
Save shello/dea96c183f9e8e7fe181ef12335b44cf to your computer and use it in GitHub Desktop.
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
# Via: https://sts10.github.io/2018/11/27/syncthing-and-tmux.html | |
# Changes to `ss` and `se`: | |
# - Start session with command on `new-session`: avoids creating a shell | |
# session just for `syncthing`; also use only `kill-session` instead of | |
# sending keys. | |
# - Test if the sessions exist (or don't exist) before creating/killing them. | |
# in ~/.bash_profile or ~/.bashrc | |
function ss { | |
if tmux has-session -t synct 2>/dev/null; then | |
echo "Syncthing session already started." >&2 | |
return 1 | |
fi | |
echo "Starting up Syncthing at http://127.0.0.1:8384/" | |
tmux new-session -d -s synct "syncthing -no-browser" | |
} | |
function se { | |
if ! tmux has-session -t synct 2>/dev/null; then | |
echo "No Syncthing session to end." >&2 | |
return 1 | |
fi | |
echo "Stopping Syncthing and killing the tmux session" | |
tmux send-keys -t synct C-c | |
} |
Regarding the error message: you can redirect that output (which tmux writes to stderr
, file descriptor 2) to /dev/null
with the shell redirection 2>/dev/null
. I made this change, along with your se
fix, to the gist!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shell script skills only improve with experience, so keep at it :)
Regarding
syncthing
remaining executing after thekill-session
, that's very interesting. I wonder if the signaltmux kill-session
is sending (I was unable to find documentation for that quickly) is being ignored bysyncthing
.Ctrl-C
sends aSIGINT
, so I'm assumingkill-session
sends another signal (maybeSIGTERM
?).If that is the case, then the
se
function you wrote probably doesn't need thekill-session
command: by sending theCtrl-C
thesyncthing
process exits, and the session should end right away.