Skip to content

Commit 94477de

Browse files
committed
Adding Connect , Search and new output messages .
1 parent 19f3d3e commit 94477de

3 files changed

Lines changed: 86 additions & 49 deletions

File tree

README.md

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ PORT and Identitykey are optional , PORT is 22 by default and Identitykey is you
2222

2323
Example :
2424
```
25-
ssc add arash root 192.168.0.100
26-
ssc add arash1 root 192.168.0.101 /home/arash/.ssh/arash.pem
27-
ssc add arash2 root 192.168.0.102 /home/arash/.ssh/arash2.pem 2223
25+
ssc add elastix root 192.168.0.100
26+
ssc add nginx root 192.168.0.101 /home/arash/.ssh/arash.pem
27+
ssc add aws-haproxy root 192.168.0.102 /home/arash/.ssh/arash2.pem 2223
2828
```
2929

3030
#### Remove a Host(Alias) :
@@ -33,8 +33,8 @@ sshconfig remove NAME
3333
```
3434
Example :
3535
```
36-
ssc remove arash1
37-
ssc remove arash2
36+
ssc remove nginx
37+
ssc remove aws-haproxy
3838
```
3939
#### List Existing Hosts(Aliases) :
4040
List all Hosts(Aliases) :
@@ -49,8 +49,20 @@ ssc list HOST
4949
```
5050
Example:
5151
```
52-
ssc list arash1
53-
>> Host arash1 HostName 192.168.0.101 User root Port 22 IdentityKey /home/arash/.ssh/arash.pem
52+
ssc list aws-haproxy
53+
>> Host: aws-haproxy HostName: 192.168.0.102 User: root Port: 22 IdentityKey: /home/arash/.ssh/arash.pem
54+
```
55+
#### Search for a Host
56+
```
57+
ssc search haproxy
58+
>> Host: haproxy-pars Hostname: 192.168.0.151 User: arash Port: 22
59+
>> Host: haproxy-afra Hostname: 192.168.1.151 User: arash Port: 22
60+
>> Host: aws-haproxy Hostname: 192.168.1.102 User: root Port: 22
61+
```
62+
#### Connect to a Host
63+
You can connect to a host if exist:
64+
```
65+
ssc aws-lsb
5466
```
5567

5668
#### Version and information
@@ -60,26 +72,17 @@ ssc version
6072
```
6173

6274
# Change log
63-
Version 1.6:
64-
- Remove comments from confg file
65-
- New name : ssc
66-
- Now lists has colored output
67-
- New install script
68-
- Fixing config file in install script
75+
Version 1.7:
76+
- Using ssc to Connect to server
77+
- Search with keywords
78+
- New output messages (Success , Error , Print)
79+
- New command aliases ( -l , -s for example )
6980

7081
# To do:
7182

72-
Connect to a host using sshconfig
73-
74-
Better output
75-
7683
Edit Host names
7784

78-
Search function with keyword
79-
8085
Share config with other Administrators
8186

82-
Adding autocomplete for bash and zsh
83-
8487
# ScreenShot
8588
![alt scrsht](https://raw.githubusercontent.com/Ara4Sh/sshconfig/master/screenshot.png)

changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Version 1.7:
2+
- Using ssc to Connect to server
3+
- Search with keywords
4+
- New output messages (Success , Error , Print)
5+
- New command aliases ( -l , -s for example )
6+
17
Version 1.6:
28
- Remove comments from confg file
39
- New name : ssc

sshconfig

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,21 @@ do_check_names() {
2929
grep "^Host" $CONFIGFILE | cut -f2- -d " "
3030
exit 0
3131
}
32-
32+
33+
success() {
34+
printf "\n \033[32mSuccess: %s\033[0m\n\n" "$@"
35+
exit 0
36+
}
37+
38+
error() {
39+
printf "\n \033[31mError: %s\033[0m\n\n" "$@"
40+
exit 1
41+
}
42+
43+
print() {
44+
printf " \033[36m%10s\033[0m : \033[90m%s\033[0m\n" "$1" "$2"
45+
}
46+
3347
do_add_process() {
3448
if [[ "$#" -eq 6 || "$#" -eq 4 ]]; then
3549
name=$2
@@ -56,13 +70,11 @@ do_add_process() {
5670
port=22
5771
fi
5872
else
59-
echo "Usage : ssc $1 NAME USERNAME HOSTNAME [IdentityKey] [PORT]"
60-
exit 1
73+
error "ssc $1 NAME USERNAME HOSTNAME [IdentityKey] [PORT]"
6174
fi
6275

6376
if [[ $(do_check_names | grep --count "^$name$") != 0 ]]; then
64-
echo "This name is already used. Try again with another name."
65-
exit 1
77+
error "This name is already used. Try again with another name."
6678
fi
6779

6880
if [ -n "$id" ]; then
@@ -83,70 +95,86 @@ Host $name
8395
Port $port
8496
EOB
8597
fi
86-
exit 0
98+
success "\"$name\" added successfuly to host list"
8799
}
88100

89101
do_remove_process() {
90102
if [ "$#" != 2 ]; then
91-
echo "Usage : ssc $1 NAME"
92-
exit 1
103+
error "Usage : ssc $1 NAME"
93104
fi
94105
name=$2
95106
if [[ $(do_check_names | grep --count "^$name$") != 0 ]]; then
96107
sed -ie "/^Host $name$/,/^$/d" $CONFIGFILE
108+
success "\"$name\" Removed successfully"
97109
exit 0
98110
else
99-
echo "Sorry, \"$name\" is not in list"
111+
error "Sorry, \"$name\" is not in list"
100112
fi
101113
}
102114

103115
do_list_process() {
104116
if [ -n "$2" ]; then
105117
name=$2
106118
if [[ $(do_check_names | grep --count "^$name$") != 0 ]]; then
107-
awk -v name="$name" -v green="\033[0;32m" -v reset="\033[0m" -v RS='' 'index($0, name) { for (i = 1; i < NF; i += 2) { printf("%s%s%s %s%s", green, $i, reset, $(i + 1), (i < NF -2)? " ": "\n") } exit }' $CONFIGFILE
119+
awk -v name="$name" -v green="\033[0;32m" -v reset="\033[0m" -v RS='' 'index($0, name) { for (i = 1; i < NF; i += 2) { printf("%s%s%s: %s%s", green, $i, reset, $(i + 1), (i < NF -2)? " ": "\n") } exit }' $CONFIGFILE
108120
exit 0
109121
else
110-
echo "Sorry, \"$name\" is not in list"
111-
exit 1
122+
error "Sorry, \"$name\" is not in list"
112123
fi
113124
else
114-
awk -v name="$name" -v green="\033[0;32m" -v reset="\033[0m" -v RS='' '{ for (i = 1; i < NF; i += 2) { printf("%s%s%s %s%s", green, $i, reset, $(i + 1), (i < NF -2)? " ": "\n") } }' $CONFIGFILE
125+
awk -v name="$name" -v green="\033[0;32m" -v reset="\033[0m" -v RS='' '{ for (i = 1; i < NF; i += 2) { printf("%s%s%s: %s\t%s", green, $i, reset, $(i + 1), (i < NF -2)? " ": "\n") } }' $CONFIGFILE
115126
fi
116127
}
117128

129+
do_connect() {
130+
name=$1
131+
if [[ $(do_check_names | grep --count "^$name$") != 0 ]]; then
132+
ssh $1
133+
exit 0
134+
fi
135+
}
136+
137+
do_search_process() {
138+
name=$2
139+
ssc ls | grep $name
140+
}
141+
118142
do_show_usage() {
119-
echo -e "Add a new Host: ssc add/-a/a NAME USERNAME HOSTNAME [IdentityKey] [PORT] "
120-
echo -e "Remove a Host: ssc remove/-r/r NAME"
121-
echo -e "List all exist hosts: ssc list/ls/show"
122-
echo -e "Print Version and info: ssc version/-v/v/-V"
123-
echo -e "Print this message and exit: ssc help/-h/h"
143+
print "Add" "ssc add/-a NAME USERNAME HOSTNAME [IdentityKey] [PORT] "
144+
print "Remove" "ssc remove/-r/rm NAME"
145+
print "List" "ssc list/-l/ls [NAME]"
146+
print "Search" "ssc search/-s NAME"
147+
print "Version" "ssc version/-v"
148+
print "Help" "ssc help/-h"
124149
}
125150

126151
do_show_version() {
127-
echo "Create by Arash Shams <xsysxpert@gmail.com>"
128-
echo "Version 1.6 Stable"
129-
echo "Fork me at Github <https://github.com/Ara4Sh/sshconfig>"
152+
print "Version" "Version 1.7 Stable"
153+
print "Contribute" "Fork me at Github <https://github.com/Ara4Sh/sshconfig>"
130154
}
131155

132156
action=$1
133157
case $action in
134-
add | -a | a)
158+
add | -a)
135159
do_add_process $@
136160
;;
137-
remove | -r | r)
161+
remove | -r | rm)
138162
do_remove_process $@
139163
;;
140-
list | ls | show)
164+
list | -l | ls)
141165
do_list_process $@
142166
;;
143-
version | -v | v | -V)
144-
do_show_version $@
167+
search | -s)
168+
do_search_process $@
145169
;;
146-
help | -h | h)
147-
do_show_usage $@
170+
version | -v)
171+
do_show_version
172+
;;
173+
help | -h)
174+
do_show_usage
148175
;;
149176
*)
177+
do_connect $@
150178
do_show_usage
151179
echo ""
152180
do_show_version

0 commit comments

Comments
 (0)