aboutsummaryrefslogtreecommitdiffstats
path: root/SshPrompt.hs
diff options
context:
space:
mode:
authorAndrea Rossato <andrea.rossato@unibz.it>2007-08-02 17:59:43 +0200
committerAndrea Rossato <andrea.rossato@unibz.it>2007-08-02 17:59:43 +0200
commitb993487a135d21aafa0129424b536890e19088ee (patch)
treecbdd4558936bb7776c8a15cb1f82255e1f328bfd /SshPrompt.hs
parentdadec6f89e8a70a1a9c15f0dc4f9ac5ac2e72fc9 (diff)
downloadXMonadContrib-b993487a135d21aafa0129424b536890e19088ee.tar.gz
XMonadContrib-b993487a135d21aafa0129424b536890e19088ee.tar.xz
XMonadContrib-b993487a135d21aafa0129424b536890e19088ee.zip
SshPrompt: a graphical prompt for ssh connection
darcs-hash:20070802155943-32816-fb564d879322995d6291898bac43afd68dbdb834.gz
Diffstat (limited to 'SshPrompt.hs')
-rw-r--r--SshPrompt.hs59
1 files changed, 59 insertions, 0 deletions
diff --git a/SshPrompt.hs b/SshPrompt.hs
new file mode 100644
index 0000000..d334636
--- /dev/null
+++ b/SshPrompt.hs
@@ -0,0 +1,59 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module : XMonadContrib.SshPrompt
+-- Copyright : (C) 2007 Andrea Rossato
+-- License : BSD3
+--
+-- Maintainer : andrea.rossato@unibz.it
+-- Stability : unstable
+-- Portability : unportable
+--
+-- A ssh prompt for XMonad
+--
+-----------------------------------------------------------------------------
+
+module XMonadContrib.SshPrompt (
+ -- * Usage
+ -- $usage
+ sshPrompt
+ ) where
+{-
+usage:
+1. In Config.hs add:
+
+> import XMonadContrib.SshPrompt
+
+3. In your keybindings add something like:
+
+> , ((modMask .|. controlMask, xK_x), xmonadPrompt defaultPromptConfig)
+
+-}
+
+import XMonad
+import XMonadContrib.XPrompt
+
+import Control.Monad
+import System.Directory
+import System.Environment
+
+data Ssh = Ssh
+
+instance XPrompt Ssh where
+ showXPrompt Ssh = "SSH to: "
+
+sshPrompt :: XPConfig -> X ()
+sshPrompt c = do
+ sc <- io $ sshComplList
+ mkXPrompt Ssh c (mkComplFunFromList sc) ssh
+
+ssh :: String -> X ()
+ssh s = spawn $ "exec xterm -e ssh " ++ s
+
+sshComplList :: IO [String]
+sshComplList = do
+ h <- getEnv "HOME"
+ let kh = h ++ "/.ssh/known_hosts"
+ f <- doesFileExist kh
+ if f then do l <- readFile kh
+ return $ map (takeWhile (/= ',') . concat . take 1 . words) (lines l)
+ else return []