Compare commits
8 Commits
jeff-99/ma
...
GHPS/ZSH-C
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6fdcf8ae6d | ||
| c528af6414 | |||
|
|
9ea667f201 | ||
| 2c8f072499 | |||
|
|
68bb493c44 | ||
| e75a733d0b | |||
| c057e1e8ed | |||
| 0266d29308 |
@@ -22,4 +22,10 @@ To run command line help:
|
||||
```
|
||||
sshch -h
|
||||
```
|
||||
**If you want to use unsafe 'password' feature you must install 'sshpass' first.**
|
||||
**If you want to use unsafe 'password' feature you must install 'sshpass' first.**
|
||||
|
||||
If you want to use bash autocompletion function with sshch, copy autocompletion script to /etc/bash_completion.d/:
|
||||
```
|
||||
sudo cp sshch_bash_completion.sh /etc/bash_completion.d/sshch
|
||||
```
|
||||
(changes will come into effect with new bash session)
|
||||
@@ -2,7 +2,7 @@ _sshch_complete()
|
||||
{
|
||||
local cur_word alias_list
|
||||
cur_word="${COMP_WORDS[COMP_CWORD]}"
|
||||
alias_list=`sshch -l | sed 's/,//g'`
|
||||
alias_list=`sshch -l`
|
||||
COMPREPLY=($(compgen -W "$alias_list" -- $cur_word))
|
||||
return 0
|
||||
}
|
||||
27
completion/sshch_zsh_completion.sh
Normal file
27
completion/sshch_zsh_completion.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
#compdef sshch
|
||||
#
|
||||
# ZSH Completion for SSHCH
|
||||
# Usage:
|
||||
# 1) Place File in a Directory where ZSH can find it
|
||||
# -> Search Path is Stored in $fpath
|
||||
# -> echo $fpath
|
||||
# 2) Rename File to '_sshch'
|
||||
#
|
||||
_arguments '::aliasname:->getAlias' \
|
||||
'-e[Edit Alias]:aliasname:->getAlias' '--edit[Edit Alias]:aliasname:->getAlias' \
|
||||
'-p[Set Password]:aliasname:->getAlias' '--password[Set Password]:aliasname:->getAlias' \
|
||||
'-r[Remove Alias]:aliasname:->getAlias' '--remove[Remove Alias]:aliasname:->getAlias' \
|
||||
'-k[Keep Connection]:aliasname:->getAlias' '--keep[Keep Connection]:aliasname:->getAlias' \
|
||||
'-a[Add Alias]' '--add[Add Alias]'\
|
||||
'-c[Add Command for Executing Alias]' '--command[Add Command for Executing Alias]'\
|
||||
'-h[Show Help Message]' '--help[Show Help Message]'\
|
||||
'-l[List Existing Alias]' '--list[List Existing Alias]'\
|
||||
'-f[List Existing Alias with Connection String]' '--fulllist[List Existing Alias with Connection String]'\
|
||||
'--version[Show Program Version]'
|
||||
case "$state" in
|
||||
getAlias)
|
||||
local -a alias_list
|
||||
alias_list=($(sshch -l))
|
||||
_values -s ' ' 'Aliases' $alias_list
|
||||
;;
|
||||
esac
|
||||
2
setup.py
2
setup.py
@@ -10,7 +10,7 @@ def main():
|
||||
url='https://github.com/zlaxy/sshch/',
|
||||
description='Ssh connection manager',
|
||||
license='DWTWL 2.5',
|
||||
version='0.7',
|
||||
version='0.8',
|
||||
py_modules=['sshch'],
|
||||
scripts=['sshch/sshch'],
|
||||
|
||||
|
||||
85
sshch/sshch
85
sshch/sshch
@@ -1,22 +1,26 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
try:
|
||||
import configparser
|
||||
except ImportError:
|
||||
import ConfigParser as configparser # Python 2.x import
|
||||
|
||||
from os import path
|
||||
from sys import argv
|
||||
from math import ceil
|
||||
from getpass import getpass
|
||||
from optparse import OptionParser
|
||||
from curses import textpad, panel
|
||||
import ConfigParser
|
||||
import subprocess
|
||||
import base64
|
||||
import curses
|
||||
import time
|
||||
|
||||
import curses
|
||||
from curses import textpad, panel
|
||||
|
||||
# https://github.com/zlaxy/sshch
|
||||
version = "0.7"
|
||||
version = "0.9"
|
||||
# path to conf file, default: ~/.config/sshch.conf
|
||||
conf_file = path.expanduser("~") + '/.config/sshch.conf'
|
||||
|
||||
@@ -54,7 +58,8 @@ def ConnectAlias(alias, command=False):
|
||||
password = base64.b32decode(base64.b16decode(
|
||||
base64.b64decode(conf.get(alias, "password"))))
|
||||
exec_string = 'sshpass -p "' + password + '" '
|
||||
exec_string = exec_string + conf.get(alias, "exec_string")
|
||||
if conf.has_option(alias, "exec_string"):
|
||||
exec_string = exec_string + conf.get(alias, "exec_string")
|
||||
if command:
|
||||
exec_string = exec_string + " " + command
|
||||
# Variables bellow is newer used
|
||||
@@ -62,7 +67,7 @@ def ConnectAlias(alias, command=False):
|
||||
|
||||
|
||||
def HoldConnection(alias):
|
||||
print "Connecting to " + alias + ". Press CTRL+C to cancel."
|
||||
print("Connecting to " + alias + ". Press CTRL+C to cancel.")
|
||||
time.sleep(1)
|
||||
while True:
|
||||
ConnectAlias(alias)
|
||||
@@ -76,10 +81,10 @@ def CMDAdd(alias):
|
||||
"(example: ssh user@somehost.com):\n"]))
|
||||
string = ""
|
||||
while string == "":
|
||||
string = raw_input(prompt_add)
|
||||
string = input(prompt_add)
|
||||
SetAliasString(alias, string)
|
||||
else:
|
||||
print result
|
||||
print(result)
|
||||
|
||||
|
||||
def CMDEdit(alias):
|
||||
@@ -88,10 +93,10 @@ def CMDEdit(alias):
|
||||
"(example: ssh user@somehost.com):\n"]))
|
||||
string = ""
|
||||
while string == "":
|
||||
string = raw_input(prompt_edit)
|
||||
string = input(prompt_edit)
|
||||
SetAliasString(alias, string)
|
||||
else:
|
||||
print "error: '" + alias + "' alias is not exists"
|
||||
print("error: '" + alias + "' alias is not exists")
|
||||
|
||||
|
||||
def CMDPassword(alias):
|
||||
@@ -102,56 +107,57 @@ def CMDPassword(alias):
|
||||
if not string == "":
|
||||
SetPassword(alias, string)
|
||||
else:
|
||||
print "error: '" + alias + "' alias is not exists"
|
||||
print("error: '" + alias + "' alias is not exists")
|
||||
|
||||
|
||||
def CMDRemove(alias):
|
||||
if conf.has_section(alias):
|
||||
prompt_remove = ("Type 'yes' if you sure to remove '" + alias + "' alias: ")
|
||||
string = raw_input(prompt_remove)
|
||||
string = input(prompt_remove)
|
||||
if string == "yes":
|
||||
RemoveAliases([alias])
|
||||
else:
|
||||
print "'" + alias + "' alias was not deleted."
|
||||
print("'" + alias + "' alias was not deleted.")
|
||||
else:
|
||||
print "error: '" + alias + "' alias is not exists."
|
||||
print("error: '" + alias + "' alias is not exists.")
|
||||
|
||||
|
||||
def CMDConnect(aliases, command=False):
|
||||
for alias in aliases:
|
||||
if conf.has_section(alias):
|
||||
print "Connecting to " + alias + "..."
|
||||
print("Connecting to " + alias + "...")
|
||||
ConnectAlias(alias, command)
|
||||
print "... " + alias + " session finished."
|
||||
print("... " + alias + " session finished.")
|
||||
else:
|
||||
print "error: '" + alias + "' alias is not exists"
|
||||
print("error: '" + alias + "' alias is not exists")
|
||||
|
||||
|
||||
def CMDList(option, opt, value, parser):
|
||||
print ', '.join(str(p) for p in conf.sections())
|
||||
print(' '.join(str(p) for p in conf.sections()))
|
||||
|
||||
|
||||
def CMDFullList(option, opt, value, parser):
|
||||
for p in conf.sections():
|
||||
to_print = "".join([str(p), " - ", conf.get(p, "exec_string"),
|
||||
(" [password]" if conf.has_option(p, "password") else ""), "\n"])
|
||||
to_print = "".join([str(p), " - ", (conf.get(p, "exec_string") if
|
||||
conf.has_option(p, "exec_string") else ""),
|
||||
(" [password]" if conf.has_option(p, "password") else "")])
|
||||
print(to_print)
|
||||
|
||||
|
||||
def CursesConnect(screen, aliases, command=False):
|
||||
curses.endwin()
|
||||
for alias in aliases:
|
||||
print "Connecting to " + alias + "..."
|
||||
print("Connecting to " + alias + "...")
|
||||
ConnectAlias(alias, command)
|
||||
print "... " + alias + " session finished."
|
||||
print "Press 'enter' to continue."
|
||||
print("... " + alias + " session finished.")
|
||||
print("Press 'enter' to continue.")
|
||||
screen.getch()
|
||||
|
||||
|
||||
def CursesExit(error=False):
|
||||
curses.endwin()
|
||||
if error:
|
||||
print error
|
||||
print(error)
|
||||
exit()
|
||||
|
||||
|
||||
@@ -332,8 +338,9 @@ def CursesMain():
|
||||
else:
|
||||
password = ""
|
||||
exec_string = ["[", selected_strings[i], "] ", str(i), " ",
|
||||
strings[i - 1], " (", conf.get(strings[i - 1], "exec_string"),
|
||||
")", password]
|
||||
strings[i - 1], " (", (conf.get(strings[i - 1],
|
||||
"exec_string") if conf.has_option(strings[i - 1],
|
||||
"exec_string") else ""), ")", password]
|
||||
if (i == position):
|
||||
box.addnstr(i, 2, "".join(exec_string), width - 6, highlight_text)
|
||||
else:
|
||||
@@ -386,7 +393,9 @@ def CursesMain():
|
||||
while edit_string.rstrip() == "":
|
||||
string_textpad = CursesTextpad(screen, 3, width - 8,
|
||||
(height // 2) - 1, 4, "Enter new execution string:",
|
||||
conf.get(strings[position - 1], "exec_string"),
|
||||
(conf.get(strings[position - 1],
|
||||
"exec_string") if conf.has_option(strings[position - 1],
|
||||
"exec_string") else ""),
|
||||
normal_text, highlight_text)
|
||||
edit_string = string_textpad.edit(CursesTextpadConfirm)
|
||||
SetAliasString(strings[position - 1],
|
||||
@@ -533,8 +542,9 @@ def CursesMain():
|
||||
else:
|
||||
password = ""
|
||||
exec_string = ["[", selected_strings[i], "] ", str(i), " ",
|
||||
strings[i - 1], " (", conf.get(strings[i - 1], "exec_string"),
|
||||
")", password]
|
||||
strings[i - 1], " (", (conf.get(strings[i - 1],
|
||||
"exec_string") if conf.has_option(strings[i - 1],
|
||||
"exec_string") else ""), ")", password]
|
||||
if (i + (max_row * (page - 1)) == (position + (max_row * (page - 1)))):
|
||||
box.addnstr(i - (max_row * (page - 1)), 2, "".join(
|
||||
exec_string), width - 6, highlight_text)
|
||||
@@ -550,7 +560,12 @@ def CursesMain():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
conf = ConfigParser.RawConfigParser()
|
||||
try:
|
||||
input = raw_input # Fix for Python 2.x
|
||||
except NameError:
|
||||
pass
|
||||
|
||||
conf = configparser.RawConfigParser()
|
||||
if not path.exists(conf_file):
|
||||
open(conf_file, 'w')
|
||||
conf.read(conf_file)
|
||||
@@ -559,15 +574,15 @@ if __name__ == "__main__":
|
||||
CMDOptions()
|
||||
except KeyboardInterrupt:
|
||||
exit()
|
||||
except ConfigParser.Error:
|
||||
print ("Error: can't parse your config file, please check it manually or make new one")
|
||||
except configparser.Error:
|
||||
print("Error: can't parse your config file, please check it manually or make new one")
|
||||
exit()
|
||||
else:
|
||||
try:
|
||||
CursesMain()
|
||||
except KeyboardInterrupt:
|
||||
CursesExit()
|
||||
except ConfigParser.NoOptionError:
|
||||
except configparser.NoOptionError:
|
||||
CursesExit("".join(["Error: can't parse your config file, please ",
|
||||
"check it manually or make new one"]))
|
||||
except curses.error:
|
||||
|
||||
Reference in New Issue
Block a user