在用于从密钥环获取密码的 Turtle 脚本中,ssh-add
使用这些密码调用以便不必手动填写,是以下函数:
processKey :: (T.Text, T.Text) -> Shell Line -> IO ()
processKey (kn, str) pwds = do
-- Not sure why (text str) is needed here, but it won't typecheck without
-- it (despite OverloadedStrings).
let expectArg = do
ml <- grep (contains (text str)) pwds
let pass = getPwd $ cut tab (format l ml)
return $ T.unlines [ "<< EOF"
, "spawn ssh-add"
, "expect \"Enter passphrase\""
, "send " <> pass
, "expect eof"
, "EOF"
]
view (inproc "expect" [] expectArg)
where
-- Safely get the third item `cut` from the list.
getPwd xs = getPwd' 0 xs
getPwd' _ [] = ""
getPwd' n (x:xs) = if n == 2
then x
else getPwd' (n+1) xs
此函数采用元组(SSH 密钥文件名,要在存储在密钥环中的文本中搜索的字符串),pwds :: Shell Line
这是从 shell 命令获取的密钥环的全部内容。
该函数的目的是获取grep
密码,并ssh-add
使用密钥文件名和密码进行调用。
问题是这个函数没有类型检查:
sshkeys-autopass.hs:45:30: error:
• Couldn't match type ‘Text’ with ‘Line’
Expected type: Shell Line
Actual type: Shell Text
• In the third argument of ‘inproc’, namely ‘expectArg’
In the first argument of ‘view’, namely
‘(inproc "expect" [] expectArg)’
In a stmt of a 'do' block: view (inproc "expect" [] expectArg)
|
45 | view (inproc "expect" [] expectArg)
| ^^^^^^^^^
好像Shell Line
需要变成Shell Text
这样,请问怎么做?我愿意接受这种结构不好或不是惯用的 Haskell 的可能性(它确实有味道),如果是这样,请告知这个功能如何更好。