diff --git a/README.md b/README.md
index 2427f77..f4a4931 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
# slist
-![](https://img.shields.io/github/release/GovTechSG/slist.svg?style=flat)
+![version](https://img.shields.io/github/release/GovTechSG/slist.svg?style=flat)
slist is a tool to list your servers in ssh config and ssh into it.
This only works on Unix machines.
@@ -7,7 +7,8 @@ slist aims to solve the problem of users having to remember aliases or IP addres
slist reads the aliases in the ~/.ssh/config file and list them in the terminal.
## Setting it up
-```
+
+```bash
cd
git clone https://github.com/GovTechSG/slist.git
chmod +x slist.sh
@@ -17,26 +18,31 @@ slist
```
## License
-This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
+This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
## Screenshots
+
![Optional Text](../master/screenshots/slist.png)
![Optional Text](../master/screenshots/filter.png)
## Usage
+
Usage: slist [-fhl]
[--add-host host_name --ip-adr ip_address [--ssh-user user --port port_number --keypath keyname_with_path]]
[--del-host host_name]
-```
+
+```bash
-f Keyword to filter
-h Display help
-l List servers with ip addresses
-l -f Filter list work
+-e Open and edit ~/.ssh/config
--add-host Add a new host to the SSH config file. Must be used together with --ip-adr option
--ip-adr Add a new IP address to the SSH config file. Must be used together with --add-host option
--ssh-user Add a new SSH user to SSH config file. Must be used together with --add-host and --ip-adr options
--port Add a new port number to SSH config file. Must be used together with --add-host and --ip-adr options
--keypath Add a new key file to SSH config file. Must be used together with --add-host and --ip-adr options
--del-host Delete a host from the SSH config file
+--config-file To use other config file
```
diff --git a/slist.sh b/slist.sh
index 06820a7..1b67ce5 100755
--- a/slist.sh
+++ b/slist.sh
@@ -26,6 +26,10 @@ Usage: slist [-hl]|[-f ]
-h Display help
-l List servers with ip addresses
-l -f Filter list work
+-e Open ~/.ssh/config
+
+Using other conf instead of default ~/.ssh/conf
+Usage: slist --config-file /tmp/config
Adding new host to ssh config
Usage: slist --add-host --ip-adr --ssh-user --port --keypath < keyname with path >
@@ -202,7 +206,7 @@ check_config_file_exists(){
# Function to check if last line of conf is empty
check_last_line(){
last_line=$(tail -1 ${config_file})
- if [ ! -z "$last_line" ]; then
+ if [ -n "$last_line" ]; then
echo "" >> "$config_file"
fi
}
@@ -221,15 +225,6 @@ check_host_exists(){
done
}
-# Start of slist
-check_config_file_exists
-
-# Loading main slist page if no argument found
-if [ $# -eq 0 ]; then
- clear
- main
-fi
-
# Function to check if argument is nil
check_arg(){
val="$1"
@@ -238,6 +233,8 @@ check_arg(){
fi
}
+# Start of slist
+check_config_file_exists
list=false
filter=false
@@ -251,16 +248,26 @@ ssh_user=false
port=false
key_path=false
-while getopts ':hlf:-:' c
+while getopts ':hlef:-:' c
do
case $c in
-)
case "$OPTARG" in
+ config-file)
+ configfile=true
+ val="${!OPTIND}"; OPTIND=$(( OPTIND + 1 ))
+ # Exit program if host is empty
+ if [[ $value == "false" ]]; then
+ printf "%s\n" "${red}Host cannot be empty ${end}"
+ exit 1
+ fi
+ config_file=$val
+ ;;
add-host)
add_host=true
val="${!OPTIND}"; OPTIND=$(( OPTIND + 1 ))
check_arg "$val"
- # Exist program if host is empty
+ # Exit program if host is empty
if [[ $value == "false" ]]; then
printf "%s\n" "${red}Host cannot be empty ${end}"
exit 1
@@ -326,6 +333,9 @@ do
filter=true
keyword=$OPTARG
;;
+ e)
+ edit=true
+ ;;
*)
echo "Invalid parameter!"
echo ""
@@ -333,9 +343,17 @@ do
;;
esac
done
-
+
+# Loading main slist page if no argument found
+if [ $# -eq 0 ] || [[ $configfile == "true" && $3 == "" ]]; then
+ clear
+ main
+fi
+
if [[ $help == "true" ]]; then
help
+elif [[ $edit == "true" ]]; then
+ vi ~/.ssh/config
elif [[ $add_host == "true" ]] && [[ $del_host == "true" ]]; then
printf "%s\n" "${red}--add-host and --del-host cannot be use at the same time ${end}"
exit 3