From ff9e95ff9ae9a6b49b591783fb87ddc4adfd65b7 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Fri, 30 May 2025 09:29:06 +0900 Subject: [PATCH] Add ignore line and skip line, more name checks lines starting with ";" are skipped, empty lines are ignored if the first line is empty (no name set) an error is thrown check that title is alphanumeric only Add a config folder for the config files (ignored) update readme file --- Readme.md | 13 +++++++++---- configs/.gitignore | 2 ++ screen_init.sh | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 configs/.gitignore diff --git a/Readme.md b/Readme.md index 776d7b1..e367759 100644 --- a/Readme.md +++ b/Readme.md @@ -8,9 +8,14 @@ Init screens from config files ```txt -# +#;; +# +; ``` -`screen session name` is the name you use for gstting the screen session name, see `screen -ls`. Must be Alphanumeric without spaces. -`window name` is the name for this window -`command` can be any comamnd sequence separated by `;`. If nothing given default `^C` shell is used +- `screen session name` is the name you use for gstting the screen session name, see `screen -ls`. Must be Alphanumeric without spaces and cannot be empty +- `window name` is the name for this window +- `command` can be any comamnd sequence separated by `;`. If nothing given default `^C` shell is used +- If there is only a `#` an empty unnamed window is opened +- if a line starts with `;` it is skipped +- empty lines are ignored diff --git a/configs/.gitignore b/configs/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/configs/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/screen_init.sh b/screen_init.sh index 4ea20cb..f4fca6c 100755 --- a/screen_init.sh +++ b/screen_init.sh @@ -78,9 +78,25 @@ export SCREENCAP="SC|screen.xterm-256color|VT 100/ANSI X3.64 virtual terminal:\ pos=0; while read -r line; do + # skip lines that start with ";" these are comments, we do not use # as they are separators + if [[ $line =~ ^\; ]]; then + continue; + fi; + # skip empty lines + if [ -n "$line" ]; then + continue; + fi; if [ $pos -eq 0 ]; then # should I clean the title to alphanumeric? (well yes, but not now) SCREEN_NAME=$line; + if [ -n "$SCREEN_NAME" ]; then + echo "No screen name set"; + exit; + fi; + if [[ ! $SCREEN_NAME =~ ^[A-Za-z0-9]+$ ]]; then + echo "Screen name must be alphanumeric: ${SCREEN_NAME}"; + exit; + fi; # check that we do not create double entries if screen -list | grep -q "${SCREEN_NAME}"; then echo "Screen with ${SCREEN_NAME} already exists";