Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
68b18f497a | ||
|
|
729124e985 | ||
|
|
d9ca21e807 | ||
|
|
1517103c60 | ||
|
|
f61e7e55bb | ||
|
|
369dcb7329 | ||
|
|
e068a6c659 | ||
|
|
7ca5f973d4 | ||
|
|
298dc19a9a | ||
|
|
95a5cda81c | ||
|
|
9293f6cd00 | ||
| ff9e95ff9a | |||
|
|
3771fd987c | ||
|
|
88d955aab8 |
2
.shellcheckrc
Normal file
2
.shellcheckrc
Normal file
@@ -0,0 +1,2 @@
|
||||
shell=bash
|
||||
external-sources=true
|
||||
15
Readme.md
15
Readme.md
@@ -6,11 +6,16 @@ Init screens from config files
|
||||
|
||||
## Config file layout
|
||||
|
||||
```
|
||||
```txt
|
||||
<screen session name>
|
||||
<window name>#<command>
|
||||
<window name>#<command>;<command>;
|
||||
#
|
||||
;<ignored line>
|
||||
```
|
||||
|
||||
`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
|
||||
|
||||
2
configs/.gitignore
vendored
Normal file
2
configs/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
@@ -25,8 +25,7 @@
|
||||
set -e
|
||||
|
||||
ERROR=0;
|
||||
if [ ! -f "$1" ];
|
||||
then
|
||||
if [ ! -f "$1" ]; then
|
||||
echo "Cannot find screen init config file '$1'";
|
||||
ERROR=1;
|
||||
else
|
||||
@@ -35,11 +34,10 @@ else
|
||||
fi;
|
||||
|
||||
# check if we are in a screen one, if yes, exit
|
||||
if [ -z "$STY" ];
|
||||
then
|
||||
if [ -z "$STY" ]; then
|
||||
# check if the "work" screen exists
|
||||
if [ ! -z "$SCREEN_NAME" ] && [[ ! -z $(screen -ls | grep ".$SCREEN_NAME\t") ]];
|
||||
then
|
||||
# if [ -n "$SCREEN_NAME" ] && [[ -n $(screen -ls | grep ".$SCREEN_NAME\t") ]];
|
||||
if [ -n "$SCREEN_NAME" ] && screen -ls | grep -q ".$SCREEN_NAME\t"; then
|
||||
echo "Screen '$SCREEN_NAME' already exists";
|
||||
ERROR=1;
|
||||
fi;
|
||||
@@ -48,11 +46,9 @@ else
|
||||
ERROR=1;
|
||||
fi;
|
||||
|
||||
if [ $ERROR -eq 1 ];
|
||||
then
|
||||
if [ $ERROR -eq 1 ]; then
|
||||
exit;
|
||||
fi;
|
||||
|
||||
# termcap (echo $TERMCAP)
|
||||
# http://web.mit.edu/gnu/doc/html/screen_15.html#SEC89
|
||||
# in screen ^-a . to dump current termcap
|
||||
@@ -79,43 +75,56 @@ export SCREENCAP="SC|screen.xterm-256color|VT 100/ANSI X3.64 virtual terminal:\
|
||||
|
||||
# read the config file and init the screen
|
||||
pos=0;
|
||||
cat "$1" |
|
||||
while read line;
|
||||
while read -r line;
|
||||
do
|
||||
if [ $pos -eq 0 ];
|
||||
then
|
||||
if [ $pos -eq 0 ]; then
|
||||
# should I clean the title to alphanumeric? (well yes, but not now)
|
||||
SCREEN_NAME=$line;
|
||||
if [ -z "$SCREEN_NAME" ]; then
|
||||
echo "[!] No screen name set";
|
||||
exit;
|
||||
fi;
|
||||
if [[ ! $SCREEN_NAME =~ ^[A-Za-z0-9-]+$ ]]; then
|
||||
echo "[!] Screen name must be alphanumeric (letters, numbers, and hyphens only): ${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";
|
||||
echo "[!] Screen with ${SCREEN_NAME} already exists";
|
||||
exit;
|
||||
fi;
|
||||
else
|
||||
# screen number is pos - 1
|
||||
SCREEN_POS=$(( pos-1 ));
|
||||
# extract screen title and command (should also be cleaned for title)
|
||||
SCREEN_TITLE=$(echo "$line" | cut -d "#" -f 1);
|
||||
SCREEN_CMD=$(echo "$line" | cut -d "#" -f 2);
|
||||
# screen number is pos - 1
|
||||
SCREEN_POS=$[ $pos-1 ];
|
||||
# skip lines that start with ";" these are comments, we do not use # as they are separators
|
||||
if [[ $line =~ ^\; ]]; then
|
||||
printf "[%2s] [SKIP] '%s' with command '%s'\n" $SCREEN_POS "$SCREEN_TITLE" "$SCREEN_CMD";
|
||||
continue;
|
||||
fi;
|
||||
# skip empty lines
|
||||
if [ -z "$line" ]; then
|
||||
continue;
|
||||
fi;
|
||||
# for the first screen, we need to init the screen and only set title
|
||||
# for the rest we set a new screen with title
|
||||
if [ $pos -eq 1 ];
|
||||
then
|
||||
echo "Init screen with title '$SCREEN_NAME'";
|
||||
if [ $pos -eq 1 ]; then
|
||||
printf "===> * INIT screen with title '%s'\n" "$SCREEN_NAME";
|
||||
screen -dmS "$SCREEN_NAME";
|
||||
# set title for the first
|
||||
screen -r "$SCREEN_NAME" -p $SCREEN_POS -X title "$SCREEN_TITLE";
|
||||
else
|
||||
screen -r "$SCREEN_NAME" -X screen -t "$SCREEN_TITLE" $SCREEN_POS;
|
||||
fi;
|
||||
echo "[$SCREEN_POS] Set title to '$SCREEN_TITLE'";
|
||||
printf "[%2s] + ADD window with title '%s'\n" $SCREEN_POS "$SCREEN_TITLE";
|
||||
# run command on it (if there is one)
|
||||
if [ ! -z "$SCREEN_CMD" ];
|
||||
then
|
||||
echo "[$SCREEN_POS] Run command '$SCREEN_CMD'";
|
||||
if [ -n "$SCREEN_CMD" ]; then
|
||||
printf " > RUN command '%s'\n" "$SCREEN_CMD";
|
||||
# if ^M is garbled: in vim do: i, ^V, ENTER, ESCAPE
|
||||
screen -r "$SCREEN_NAME" -p $SCREEN_POS -X stuff $"$SCREEN_CMD^M";
|
||||
fi;
|
||||
fi;
|
||||
pos=$[ $pos+1 ];
|
||||
done;
|
||||
pos=$(( pos+1 ));
|
||||
done <<<"$(cat "${1}")";
|
||||
|
||||
Reference in New Issue
Block a user