codehenry / xmonad

Automatically exported from code.google.com/p/xmonad
0 stars 0 forks source link

XMonad.Prompt.Shell should use user-defined searchPredicate #393

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Set-up XMonad.Prompt.Shell with defaulXPConfig changing the 
searchPredicate to something else. e.g. \x y -> map toLower x `isPrefixOf` 
map toLower y
2. run your prompt, start typing anything to see that your searchPredicate 
is ignored. In the above example case IS ignored, so typing 'VI' should 
show 'vi' or 'vim' on the list, but they're not.

What version of the product are you using? On what operating system?
latest darcs on up-to-date Archlinux x86_64

Are you using an xmonad.hs?  Please attach it and the output of "xmonad
--recompile".
recompile prints nothing and my cluttered xmonad.hs is attached but only 
line 166 is related (which is a keybind to X.A.SpawnOn shellPromptHere).

Please provide any additional information below.
X.P.Shell also completes filenames using bash's compgen, it should respect 
user's setting (~/.inputrc) telling it to ignore-case (set completion-
ignore-case on). But that's another problem, I'm just complaining about 
command completion for now.

Original issue reported on code.google.com by hgabreu on 28 Apr 2010 at 11:37

Attachments:

GoogleCodeExporter commented 8 years ago
I've managed to set up Shell the way I wanted, which is ignoring case.
It may help anyone willing to correct/enhance XMonad.Prompt.Shell, I don't do 
it 
myself because I'm very bad at haskell and don't how to do it right, flexible, 
etc.

I copied X.P.Shell getShellCompl and commandCompletionFunction to my config 
(attached) and changed them to this:
getShellCompl cmds s | s == "" || last s == ' ' = return []
                     | otherwise                = do
    f     <- fmap lines $ runProcessWithInput "bash" [] ("bind 'set completion-
ignore-case on'; compgen -A file " ++ encodeOutput s ++ "\n")
...the rest of the function is the same...

commandCompletionFunction cmds str | '/' `elem` str = []
                                   | otherwise = filter ((\x y -> map toLower x 
`isPrefixOf` map toLower y) str) cmds

Oh! I don't think anyone will ever try this config as is, but is one does, 
change the 
layoutHook because it won't run ok. I edited MouseResizableTile here to play 
with 
SubLayouts.

Original comment by hgabreu on 28 Apr 2010 at 2:02

Attachments:

GoogleCodeExporter commented 8 years ago
Hi,

I just fixed (at least for me) the issue shellPrompt ignores searchPredicate 
field of XPConfig record.
After applying my patch, you can now create/combine whatever function you want 
and it will by used at filtering of shell commands completion.

Just set searchPredicate field and pass it to shellPrompt.
Of my xmonad.hs config:
import qualified Data.List as L
import Data.Char
...
   , ((myModMask, xK_x),     shellPrompt defaultXPConfig 
                    {
                      -- match a substring anywhere within and ignore case
                      searchPredicate = L.isInfixOf . (map toLower)
                      ...
                    }

Patch created for xmonad-contrib ver. 0.10

Take care

:-)

Original comment by dunric...@gmail.com on 1 Feb 2012 at 7:52

Attachments:

GoogleCodeExporter commented 8 years ago
Anyone have any thoughts? The only type/API change is to 'getShellCompl', which 
is not used in any of the configs in my archive (one config hides it and 
redefines it).

Original comment by gwe...@gmail.com on 5 Feb 2012 at 12:13

GoogleCodeExporter commented 8 years ago
Looks good to me.

Original comment by dan...@schoepe.org on 15 Feb 2012 at 5:03

GoogleCodeExporter commented 8 years ago
Hi,

me again. As a search predicate for shellPrompt is still not implemented in an 
upstream, here is the updated patch to xmonad-contrib 0.11 sources.

In addition to the previous version it sorts list of the possible commands not 
only alphabetically but also favours commands starting with the same sequence 
as typed in prompt. Similar behaviour seen at dmenu launcher.
For example my search predicate for XMonad.Prompt.Shell.shellPrompt matches 
anywhere inside of possible command names, not only at their begining and 
ignoring case at the same time:
    searchPredicate = L.isInfixOf . map toLower

Now when trying to launch a firefox browser and type "fire" at xmonad's 
shellPrompt I'm getting the following completions in that order:
firefox aafire cacafire

Original comment by dunric...@gmail.com on 2 Feb 2013 at 4:01

Attachments: