Skip to content

Instantly share code, notes, and snippets.

@wtbarnes
Created January 9, 2022 20:32
Show Gist options
  • Save wtbarnes/69ec92b168167598cdea3d66ba4f8e75 to your computer and use it in GitHub Desktop.
Save wtbarnes/69ec92b168167598cdea3d66ba4f8e75 to your computer and use it in GitHub Desktop.
Useful function for doing things inside of screen commands
# Useful functions for managing things in detached screen sessions
# Starts zotero in headless mode in a screen session using xvfb
zotero_headless () {
screen -dm -S "zotero-headless" bash -c "cd $HOME/.local/Zotero_linux-x86_64; xvfb-run ./zotero"
}
# Start and stop a headless zotero session
zotero_start_stop () {
zotero_headless
sleep 10
screen_ctrl_c zotero-headless
}
# Start a hydrad run in a detached screen session
# First argument is directory with the configured HYDRAD instances
# The initial conditions have already been run and the code has
# been compiled
hydrad_screen () {
screen -dm -S "$(echo $1 | tr / _)" bash -c "cd $1; ./HYDRAD.exe > job.status"
}
# Takes all the hydrad runs in a given directory and starts
# each one in a separate screen session. Should be used with caution
# if doing so with many files
hydrad_screen_dir () {
for f in "$1"/*
do
hydrad_screen $f
done
}
# Send a "Ctrl-C" to a detached screen session
screen_ctrl_c () {
screen -S $1 -X stuff "^C"
}
# Kill a detached screen session
screen_kill () {
screen -X -S $1 quit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment