-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto-startup
executable file
·145 lines (111 loc) · 4.3 KB
/
auto-startup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
# Auto Startup
# Purpose: This script opens new tabs in terminal and executes custom commands automatically.
# Author: Daniel Okwufulueze
# Date: 14/05/2017
helpText=;
scriptAbsolutePath=;
function getAbsolutePathOfSelf() {
pushd $(dirname "$0") > /dev/null;
scriptAbsolutePath="$(pwd -P)";
popd > /dev/null;
}
function displayHowToUse() {
helpText=$(cat << EOF
Auto Startup
Version: 2.0.0
Usage: auto-startup [-h | --help]
auto-startup [-c | --command quoted-semicolon-separated-commands]
auto-startup [-f | --file-name fileName]
auto-startup [-c | --command quoted-semicolon-separated-commands]
[[-b | --black-hole] | [-n | --nohup] | [-o | --output file-path]]
auto-startup [-f | --file-name fileName]
[[-b | --black-hole] | [-n | --nohup] | [-o | --output file-path]]
Synopsis:
Purpose: This script opens new tabs in terminal and
excutes custom commands automatically.
It sends command output to either nohup.out, the /dev/null black hole,
or a custom file, depending on the option selected by the user.
Options:
-c | --command: This option receives the list of your custom commands in
quoted string all separated by semicolons [;].
For example: auto-startup -c "cd daniel; do_something; do_another_thing".
-f | --file-name: This option receives the name of the file containing
all the commands you want to run.
Each command in the file should take a
line [separate commands with new line characters].
-h | --help: This option displays this help page.
Flags:
-b | --black-hole: If this flag is set, then all output from the
running processes will be redirected to the /dev/null black-hole.
-n | --nohup: This flag creates a nohup.out file in the working
directories of the running processes and redirects all output
from the running processes to the nohup.out file.
-o | --output: The --output flag takes the path of the file you
intend to use for output of running processes.
If the file does not exist, it will be created.
All output from the running processes will be redirected
to the specified file of the --output flag.
If no flag is supplied, then output will be written to stdin.
Author: Daniel Okwufulueze [https://github.com/DOkwufulueze]
Date: 14/05/2017
EOF
);
}
getAbsolutePathOfSelf;
. "${scriptAbsolutePath}/startup-manager";
setupManagerForEntity;
if [[ $# -gt 0 ]]; then
while [[ "$1" != "" ]]; do
case "$1" in
-b | --black-hole )
outputStream="black-hole";
;;
-c | --command )
shift;
commandText="$1"
determineEntryValidity "${commandText}" 20 21;
IFS=";" read -ra TEMP_SHELL_COMMANDS <<< "${commandText}";
;;
-f | --file-name )
shift;
fileName=$1;
determineEntryValidity "${fileName}" 30 31;
populateShellCommandsFromFile "${fileName}";
;;
-h | --help )
displayHowToUse;
echo "${helpText}" | less;
exit;
;;
-n | --nohup )
outputStream="nohup";
;;
-o | --output )
shift;
outputFile="$1";
determineEntryValidity "${outputFile}" 60 61;
outputStream="custom";
createFileIfNotExists "" "/";
;;
* )
echo "Invalid entry in auto-startup invocation.";
exit;
;;
esac
shift;
done
formatShellCommands;
fi
if [[ ${#SHELL_COMMANDS[@]} -gt 0 ]]; then
# Loop through the array of commands and execute each one on a new tab
for ((i = 0; i < ${#SHELL_COMMANDS[@]}; i++)); do
SHELL_COMMAND="${SHELL_COMMANDS[$i]}";
export DISPLAY=:0.0 && xdotool key ctrl+shift+t;
sleep 2;
xdotool type --delay 1 --clearmodifiers "${SHELL_COMMAND}";
xdotool key Return;
done
else
echo "No Command was supplied to auto-startup";
fi