mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-08-14 19:55:55 -07:00
It turns out that for urxvt, and most terminal, apparently, once you give a '-e' option, that's it. They will not interpret anything after that as anything but input for /bin/sh, so if you wanted to go 'runInTerm "'screen -r session' -title IRC"', you were SOL - the -title would not be seen by urxvt. This, needless to say, is bad, since then you can't do stuff like set the title which means various hooks and extensions are helpless. This patch adds an extra options argument which is inserted *before* the -e. If you want the old behaivour, you can just go 'runInTerm "" "executable"', but now if you need to do something extra, 'runInTerm "-title mutt" "mutt"' works fine. This patch also updates callers.
106 lines
2.8 KiB
Haskell
106 lines
2.8 KiB
Haskell
-----------------------------------------------------------------------------
|
|
-- |
|
|
-- Module : XMonad.Prompt.Ssh
|
|
-- Copyright : (C) 2007 Andrea Rossato
|
|
-- License : BSD3
|
|
--
|
|
-- Maintainer : andrea.rossato@unibz.it
|
|
-- Stability : unstable
|
|
-- Portability : unportable
|
|
--
|
|
-- A ssh prompt for XMonad
|
|
--
|
|
-----------------------------------------------------------------------------
|
|
|
|
module XMonad.Prompt.Ssh(
|
|
-- * Usage
|
|
-- $usage
|
|
sshPrompt
|
|
) where
|
|
|
|
import XMonad
|
|
import XMonad.Util.Run
|
|
import XMonad.Prompt
|
|
|
|
import System.Directory
|
|
import System.Environment
|
|
|
|
import Control.Monad
|
|
import Data.List
|
|
import Data.Maybe
|
|
|
|
-- $usage
|
|
-- 1. In your @~\/.xmonad\/xmonad.hs@:
|
|
--
|
|
-- > import XMonad.Prompt
|
|
-- > import XMonad.Prompt.Ssh
|
|
--
|
|
-- 2. In your keybindings add something like:
|
|
--
|
|
-- > , ((modMask x .|. controlMask, xK_s), sshPrompt defaultXPConfig)
|
|
--
|
|
-- Keep in mind, that if you want to use the completion you have to
|
|
-- disable the "HashKnownHosts" option in your ssh_config
|
|
--
|
|
-- For detailed instruction on editing the key binding see
|
|
-- "XMonad.Doc.Extending#Editing_key_bindings".
|
|
|
|
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 = runInTerm "" ("ssh " ++ s)
|
|
|
|
sshComplList :: IO [String]
|
|
sshComplList = uniqSort `fmap` liftM2 (++) sshComplListLocal sshComplListGlobal
|
|
|
|
sshComplListLocal :: IO [String]
|
|
sshComplListLocal = do
|
|
h <- getEnv "HOME"
|
|
sshComplListFile $ h ++ "/.ssh/known_hosts"
|
|
|
|
sshComplListGlobal :: IO [String]
|
|
sshComplListGlobal = do
|
|
env <- getEnv "SSH_KNOWN_HOSTS" `catch` (\_ -> return "/nonexistent")
|
|
fs <- mapM fileExists [ env
|
|
, "/usr/local/etc/ssh/ssh_known_hosts"
|
|
, "/usr/local/etc/ssh_known_hosts"
|
|
, "/etc/ssh/ssh_known_hosts"
|
|
, "/etc/ssh_known_hosts"
|
|
]
|
|
case catMaybes fs of
|
|
[] -> return []
|
|
(f:_) -> sshComplListFile' f
|
|
|
|
sshComplListFile :: String -> IO [String]
|
|
sshComplListFile kh = do
|
|
f <- doesFileExist kh
|
|
if f then sshComplListFile' kh
|
|
else return []
|
|
|
|
sshComplListFile' :: String -> IO [String]
|
|
sshComplListFile' kh = do
|
|
l <- readFile kh
|
|
return $ map (takeWhile (/= ',') . concat . take 1 . words)
|
|
$ filter nonComment
|
|
$ lines l
|
|
|
|
fileExists :: String -> IO (Maybe String)
|
|
fileExists kh = do
|
|
f <- doesFileExist kh
|
|
if f then return $ Just kh
|
|
else return Nothing
|
|
|
|
nonComment :: String -> Bool
|
|
nonComment [] = False
|
|
nonComment ('#':_) = False
|
|
nonComment ('|':_) = False -- hashed, undecodeable
|
|
nonComment _ = True
|