Add shellcheckrc, clean up code
This commit is contained in:
2
.shellcheckrc
Normal file
2
.shellcheckrc
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
shell=bash
|
||||||
|
external-sources=true
|
||||||
@@ -25,8 +25,7 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
ERROR=0;
|
ERROR=0;
|
||||||
if [ ! -f "$1" ];
|
if [ ! -f "$1" ]; then
|
||||||
then
|
|
||||||
echo "Cannot find screen init config file '$1'";
|
echo "Cannot find screen init config file '$1'";
|
||||||
ERROR=1;
|
ERROR=1;
|
||||||
else
|
else
|
||||||
@@ -35,11 +34,10 @@ else
|
|||||||
fi;
|
fi;
|
||||||
|
|
||||||
# check if we are in a screen one, if yes, exit
|
# check if we are in a screen one, if yes, exit
|
||||||
if [ -z "$STY" ];
|
if [ -z "$STY" ]; then
|
||||||
then
|
|
||||||
# check if the "work" screen exists
|
# check if the "work" screen exists
|
||||||
if [ ! -z "$SCREEN_NAME" ] && [[ ! -z $(screen -ls | grep ".$SCREEN_NAME\t") ]];
|
# if [ -n "$SCREEN_NAME" ] && [[ -n $(screen -ls | grep ".$SCREEN_NAME\t") ]];
|
||||||
then
|
if [ -n "$SCREEN_NAME" ] && screen -ls | grep -q ".$SCREEN_NAME\t"; then
|
||||||
echo "Screen '$SCREEN_NAME' already exists";
|
echo "Screen '$SCREEN_NAME' already exists";
|
||||||
ERROR=1;
|
ERROR=1;
|
||||||
fi;
|
fi;
|
||||||
@@ -48,8 +46,7 @@ else
|
|||||||
ERROR=1;
|
ERROR=1;
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
if [ $ERROR -eq 1 ];
|
if [ $ERROR -eq 1 ]; then
|
||||||
then
|
|
||||||
exit;
|
exit;
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
@@ -79,11 +76,9 @@ export SCREENCAP="SC|screen.xterm-256color|VT 100/ANSI X3.64 virtual terminal:\
|
|||||||
|
|
||||||
# read the config file and init the screen
|
# read the config file and init the screen
|
||||||
pos=0;
|
pos=0;
|
||||||
cat "$1" |
|
while read -r line;
|
||||||
while read line;
|
|
||||||
do
|
do
|
||||||
if [ $pos -eq 0 ];
|
if [ $pos -eq 0 ]; then
|
||||||
then
|
|
||||||
# should I clean the title to alphanumeric? (well yes, but not now)
|
# should I clean the title to alphanumeric? (well yes, but not now)
|
||||||
SCREEN_NAME=$line;
|
SCREEN_NAME=$line;
|
||||||
# check that we do not create double entries
|
# check that we do not create double entries
|
||||||
@@ -96,11 +91,10 @@ do
|
|||||||
SCREEN_TITLE=$(echo "$line" | cut -d "#" -f 1);
|
SCREEN_TITLE=$(echo "$line" | cut -d "#" -f 1);
|
||||||
SCREEN_CMD=$(echo "$line" | cut -d "#" -f 2);
|
SCREEN_CMD=$(echo "$line" | cut -d "#" -f 2);
|
||||||
# screen number is pos - 1
|
# screen number is pos - 1
|
||||||
SCREEN_POS=$[ $pos-1 ];
|
SCREEN_POS=$(( pos-1 ));
|
||||||
# for the first screen, we need to init the screen and only set title
|
# for the first screen, we need to init the screen and only set title
|
||||||
# for the rest we set a new screen with title
|
# for the rest we set a new screen with title
|
||||||
if [ $pos -eq 1 ];
|
if [ $pos -eq 1 ]; then
|
||||||
then
|
|
||||||
echo "Init screen with title '$SCREEN_NAME'";
|
echo "Init screen with title '$SCREEN_NAME'";
|
||||||
screen -dmS "$SCREEN_NAME";
|
screen -dmS "$SCREEN_NAME";
|
||||||
# set title for the first
|
# set title for the first
|
||||||
@@ -110,12 +104,11 @@ do
|
|||||||
fi;
|
fi;
|
||||||
echo "[$SCREEN_POS] Set title to '$SCREEN_TITLE'";
|
echo "[$SCREEN_POS] Set title to '$SCREEN_TITLE'";
|
||||||
# run command on it (if there is one)
|
# run command on it (if there is one)
|
||||||
if [ ! -z "$SCREEN_CMD" ];
|
if [ -n "$SCREEN_CMD" ]; then
|
||||||
then
|
|
||||||
echo "[$SCREEN_POS] Run command '$SCREEN_CMD'";
|
echo "[$SCREEN_POS] Run command '$SCREEN_CMD'";
|
||||||
# if ^M is garbled: in vim do: i, ^V, ENTER, ESCAPE
|
# if ^M is garbled: in vim do: i, ^V, ENTER, ESCAPE
|
||||||
screen -r "$SCREEN_NAME" -p $SCREEN_POS -X stuff $"$SCREEN_CMD^M";
|
screen -r "$SCREEN_NAME" -p $SCREEN_POS -X stuff $"$SCREEN_CMD^M";
|
||||||
fi;
|
fi;
|
||||||
fi;
|
fi;
|
||||||
pos=$[ $pos+1 ];
|
pos=$(( pos+1 ));
|
||||||
done;
|
done <<<"$(cat "${1}")";
|
||||||
|
|||||||
Reference in New Issue
Block a user