changeset 9:cb9c1d42c201

ssh: rework using dmenu.subr
author David Demelier <markand@malikania.fr>
date Tue, 07 Nov 2017 12:04:08 +0100
parents e1e0929d3189
children 34563a7481c2
files dmenu_ssh
diffstat 1 files changed, 23 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/dmenu_ssh	Tue Nov 07 12:03:56 2017 +0100
+++ b/dmenu_ssh	Tue Nov 07 12:04:08 2017 +0100
@@ -2,7 +2,7 @@
 #
 # dmenu_ssh -- ssh prompt for dmenu
 #
-# Copyright (c) 2016 David Demelier <markand@malikania.fr>
+# Copyright (c) 2016-2017 David Demelier <markand@malikania.fr>
 #
 # Permission to use, copy, modify, and/or distribute this software for any
 # purpose with or without fee is hereby granted, provided that the above
@@ -17,22 +17,34 @@
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #
 
-if ! which dmenu > /dev/null 2>&1; then
-    echo "missing dmenu" 1>&2;
-    exit 1
+if [ -r dmenu.subr ]; then
+    . ./dmenu.subr
+fi
+if [ -r /usr/local/libexec/dmenutools/dmenu.subr ]; then
+    . /usr/local/libexec/dmenutools/dmenu.subr
+fi
+
+# Default user values.
+: "${ssh_lines:=0}"
+
+# Requirements.
+if [ -z "${term}" ]; then
+    dmt_fatal "no terminal set, see dmenutools.conf"
 fi
 if ! which ssh > /dev/null 2>&1; then
-    echo "missing ssh" 1>&2;
-    exit 1
+    dmt_fatal "missing ssh"
+fi
+if [ ! -r "${HOME}/.ssh/config" ]; then
+    dmt_fatal "missing ${HOME}/.ssh/config" 1>&2;
 fi
 
-if [ ! -r "${HOME}/.ssh/config" ]; then
-    echo "missing ${HOME}/.ssh/config" 1>&2;
-    exit 1;
+args="-p ssh"
+
+if [ "${ssh_lines}" -gt 0 ]; then
+    args="-l ${ssh_lines} ${args}"
 fi
 
-term=${1:-xterm}
-host=$(grep -Ei "Host\s" ${HOME}/.ssh/config | awk '{ print $2 '} | dmenu -p ssh)
+host=$(grep -Ei "Host\s" ${HOME}/.ssh/config | awk '{ print $2 '} | dmenu ${args})
 
 if [ -n "${host}" ]; then
     ${term} -e ssh ${host}