Skip to content

Commit

Permalink
Merge branch 'master' into issue_12_save_all_sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwalz authored Jul 20, 2024
2 parents 35835ba + 6d44e46 commit 41f9149
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 12 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/differential-shellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Differential ShellCheck
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest

permissions:
# required for all workflows
security-events: write

# only required for workflows in private repositories
actions: read
contents: read

steps:
- name: Repository checkout
uses: actions/checkout@v4
with:
# Differential ShellCheck requires full git history
fetch-depth: 0

- id: ShellCheck
name: Differential ShellCheck
uses: redhat-plumbers-in-action/differential-shellcheck@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}

- if: always()
name: Upload artifact with ShellCheck defects in SARIF format
uses: actions/upload-artifact@v4
with:
name: Differential ShellCheck SARIF
path: ${{ steps.ShellCheck.outputs.sarif }}
23 changes: 12 additions & 11 deletions screen-save
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ C=""
write() {
if test "$1" = "-n"; then
shift;
C="${C}$@"
C="${C}$*"
return
fi
C="${C}$@
C="${C}$*
"
}

doublequote() {
local output
for i in "$@"
do
i=${i//\\/\\\\}
Expand Down Expand Up @@ -70,8 +69,10 @@ read_cmdline() {
do
if test "$(echo "${ARG}" | tr -d 'A-Za-z0-9.=_-')" = ""
then
# shellcheck disable=SC2059
printf "${format}" "${ARG}"
else
# shellcheck disable=SC2059
printf "${format}" "$(escape_shell "${ARG}")"
fi
format=" %s"
Expand Down Expand Up @@ -106,7 +107,7 @@ then
exit 1
fi
# session name in sty is not updated.
SCREEN_PID="$(echo ${STY} | grep -oE "^\s*[0-9]+" | grep -oE "[0-9]+")"
SCREEN_PID="$(echo "${STY}" | grep -oE "^\s*[0-9]+" | grep -oE "[0-9]+")"
C_SCREEN_NAME="$2"
SAVE_FILE="$3"
else
Expand All @@ -125,7 +126,7 @@ then
fi

# get sessionname from screen:
SCREEN_NAME="$(screen -S ${SCREEN_PID} -Q echo '${STY}')"
SCREEN_NAME="$(screen -S "${SCREEN_PID}" -Q echo "\${STY}")"

# screen id is pid + name:
SCREEN_ID="${SCREEN_PID}.${SCREEN_NAME}"
Expand All @@ -145,14 +146,14 @@ if test "${C_SCREEN_NAME}" != ""; then
SCREEN_NAME="${C_SCREEN_NAME}"
fi
if test "${SCREEN_NAME}" = ""; then
read -p "The screen session does not have a name. Please set one: " SCREEN_NAME
read -r -p "The screen session does not have a name. Please set one: " SCREEN_NAME
fi
if test "${SCREEN_NAME}" = ""; then
SCREEN_NAME="pid-${SCREEN_SEARCH}"
fi

# get screens cwd:
SCREEN_CWD="$(screen -S "${SCREEN_ID}" -Q echo '${PWD}')"
SCREEN_CWD="$(screen -S "${SCREEN_ID}" -Q echo "\${PWD}")"

write "# from .screenrc (filtered):"
write "$(grep -Ei "^(def|source|colon|setenv|unsetenv|shell|shelltitle|term|password|lockscreen|multiuser|acladd|addacl|aclchg|chacl|acldel|aclgrp|aclumask|umask|wall|resize|caption|fit|mousetrack|width|height|utf8|scrollback|bind|unbindall|escape|meta|dump|echo|sleep|log|startup_message|debug|crlf|caption)" "${HOME}/.screenrc" 2>/dev/null)"
Expand All @@ -162,8 +163,8 @@ write "# saved session:"
write "sessionname \"${SCREEN_NAME}\""
write

debug SCREENNAME=${SCREEN_NAME}
debug SCREEN_ID=${SCREEN_ID}
debug "SCREENNAME=${SCREEN_NAME}"
debug "SCREEN_ID=${SCREEN_ID}"
debug "path: ${SCREEN_CWD}"
debug

Expand All @@ -179,14 +180,14 @@ do
# The window number is read from the environment, which can not
# be updated by screen.
WINDOW_ID="$(xargs --null --max-args=1 echo \
</proc/${WINDOW_PID}/environ | grep -w WINDOW | grep -oE "[0-9]+")"
<"/proc/${WINDOW_PID}/environ" | grep -w WINDOW | grep -oE "[0-9]+")"

# read cmdline:
WINDOW_CL="$(read_cmdline "${WINDOW_PID}")"


# get cwd of window:
WINDOW_CWD="$(readlink /proc/${WINDOW_PID}/cwd)"
WINDOW_CWD="$(readlink "/proc/${WINDOW_PID}/cwd")"

# get title of window:
WINDOW_TITLE="$(screen -S "${SCREEN_ID}" -p "${WINDOW_ID}" -Q title)"
Expand Down
2 changes: 1 addition & 1 deletion screen-save-all-sessions
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# save all my screen sessions
# Simon Walz, 2018

SCRIPTPATH="$(readlink -f 2>/dev/null || perl -MCwd -e 'print Cwd::abs_path shift' $0)"
SCRIPTPATH="$(readlink -f 2>/dev/null || perl -MCwd -e 'print Cwd::abs_path shift' "$0")"
SCRIPTDIR="$(dirname "${SCRIPTPATH}")"

set -e
Expand Down

0 comments on commit 41f9149

Please sign in to comment.