From b993487a135d21aafa0129424b536890e19088ee Mon Sep 17 00:00:00 2001 From: Andrea Rossato Date: Thu, 2 Aug 2007 17:59:43 +0200 Subject: SshPrompt: a graphical prompt for ssh connection darcs-hash:20070802155943-32816-fb564d879322995d6291898bac43afd68dbdb834.gz --- SshPrompt.hs | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 SshPrompt.hs 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 [] -- cgit v1.2.3