-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathihsec.sh
executable file
·102 lines (88 loc) · 2.62 KB
/
ihsec.sh
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
#!/bin/bash
CONFIGS_DIR=$HOME'/.ihsec/'
# Uncomment to use this script from the same folder as emacs configs
#CONFIGS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo " Configuration directory: "$CONFIGS_DIR
CONFIGDIRS="$CONFIGS_DIR/*/"
EMACSDIR=$HOME'/.emacs.d'
function displayHelp
{
echo -e " Usage:\n\t'ihsec' - To view this help menu.\n\t'ihsec list' - To view a list of available configurations."
echo -e "\t'ihsec set <config>' - To set a configuration.\n\t'ihsec del <config>' - To delete a config."
echo -e "\t'ihsec install <url_to_git_repo> <name_for_the_config>' - To install a configuration via git."; exit 1
}
function displayError
{
echo -e " Something went wrong!\n Ensure ~/.emacs.d is a symlink or does not exist!"; exit $?
}
function displayArgError
{
echo -e " Wrong number of arguments entered.\n Use 'ihsec help' or 'ihsec' to learn about the usage."; exit 1
}
if [ "$#" -eq 0 ]; then displayHelp; fi
case "$1" in
list)
if [ ! "$#" -eq 1 ]; then displayArgError; fi
CURR_CONFIG=$(basename $(readlink -f $HOME/.emacs.d/))
echo -e " Available configurations:"
for DIR in $CONFIGDIRS; do
if [[ -d $DIR ]]; then
if [[ $DIR == *"$CURR_CONFIG"* ]]; then echo -en "->"; else echo -en " "; fi
echo -en " \u2022" $(basename $DIR)"\n"
fi
done
;;
set)
if [ ! "$#" -eq 2 ]; then displayArgError; fi
if [ -d "$CONFIGS_DIR/$2" ]; then
unlink $EMACSDIR &> /dev/null
ln -s "$CONFIGS_DIR/$2" $EMACSDIR
if [[ $? != 0 ]]; then
displayError
else
echo "Configuration $2 set!"
fi
else
echo "Invalid configuration name, ensure it exists!"; exit 1
fi
;;
del)
if [ ! "$#" -eq 2 ]; then displayArgError; fi
if [ -d "$CONFIGS_DIR/$2" ]; then
read -rsn1 -p "Are you sure? This can not be undone! [y/n]: " yn
case $yn in
[Yy]* )
rm -rf "$CONFIGS_DIR/$2"
if [[ $? != 0 ]]; then
displayError
else
echo -e "\nConfiguration $2 removed!"
fi
;;
[Nn]* )
echo -e "\nExiting..."
exit 1
;;
* ) echo -e "\nPlease answer 'y' or 'n'.";;
esac
else
echo " Invalid configuration name, ensure it exists!"
exit 1
fi
;;
install)
if [ ! "$#" -eq 3 ]; then displayArgError; fi
echo "Installing $3 from $2..."
git clone $2 "$CONFIGS_DIR/$3" &> /dev/null
if [[ $? != 0 ]]; then
echo "Something went wrong, ensure your connection is stable and the link is valid."
else
echo "Installed $3 successfully!"
fi
;;
help)
if [ ! "$#" -eq 1 ]; then displayArgError; fi; displayHelp
;;
*)
echo -e " Unknown command entered.\n Use 'ihsec help' or 'ihsec' to learn about the usage."
esac