XMonad.Prompt.File (attached)

Hello, I had need in my config for a filename prompt. XMonad-Contrib contains XMonad.Prompt.Directory, so I just copied it and made the appropriate substitutions to make XMonad.Prompt.File. It would be great if this could be added to xmonad-contrib so it will be there for the next person who needs this functionality. -- John Foerch

On Wed, Mar 16, 2011 at 10:45 PM, John J Foerch
I had need in my config for a filename prompt. XMonad-Contrib contains XMonad.Prompt.Directory, so I just copied it and made the appropriate substitutions to make XMonad.Prompt.File. It would be great if this could be added to xmonad-contrib so it will be there for the next person who needs this functionality.
Well, as you say, it's basically just a copy-paste with one small change: 36,38c36,38 < getFileCompl :: String -> IO [String] < getFileCompl s = (filter notboring . lines) `fmap` < runProcessWithInput "/bin/bash" [] ("compgen -A file " ++ s ++ "\n") ---
getDirCompl :: String -> IO [String] getDirCompl s = (filter notboring . lines) `fmap` runProcessWithInput "/bin/bash" [] ("compgen -A directory " ++ s ++ "\n")
As it stands, I would be adamantly against inclusion; such copy-paste is not the Haskell way. Surely there is a better approach? I can't help but suspect that this functionality may already be supplied by another module (perhaps the Shell prompt meets your needs). (On a side-note, I'm a little horrified by the 'notboring' function. Is there really no library function for that? I quickly looked in System.Filepath and System.Directory but turned up nothing named along the lines of 'isHidden'.) -- gwern http://www.gwern.net

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 3/17/11 22:21 , Gwern Branwen wrote:
(On a side-note, I'm a little horrified by the 'notboring' function. Is there really no library function for that? I quickly looked in System.Filepath and System.Directory but turned up nothing named along the lines of 'isHidden'.)
isHidden would have some serious portability issues. - -- brandon s. allbery [linux,solaris,freebsd,perl] allbery.b@gmail.com system administrator [openafs,heimdal,too many hats] kf8nh -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk2CzFsACgkQIn7hlCsL25XbOQCfXqE/yqiMnft2unumSOR4ACsy 2mEAnj0EWil/uZnxM9jdF2gtrI358/B0 =8Gsg -----END PGP SIGNATURE-----

Gwern Branwen
On Wed, Mar 16, 2011 at 10:45 PM, John J Foerch
wrote: I had need in my config for a filename prompt. XMonad-Contrib contains XMonad.Prompt.Directory, so I just copied it and made the appropriate substitutions to make XMonad.Prompt.File. It would be great if this could be added to xmonad-contrib so it will be there for the next person who needs this functionality.
Well, as you say, it's basically just a copy-paste with one small change:
36,38c36,38 < getFileCompl :: String -> IO [String] < getFileCompl s = (filter notboring . lines) `fmap` < runProcessWithInput "/bin/bash" [] ("compgen -A file " ++ s ++ "\n") ---
getDirCompl :: String -> IO [String] getDirCompl s = (filter notboring . lines) `fmap` runProcessWithInput "/bin/bash" [] ("compgen -A directory " ++ s ++ "\n")
As it stands, I would be adamantly against inclusion; such copy-paste is not the Haskell way. Surely there is a better approach? I can't help but suspect that this functionality may already be supplied by another module (perhaps the Shell prompt meets your needs).
Sorry it couldn't be a more profound, creative, and interesting module :D but that's what I needed. Shell prompt does not fit the bill for two reasons: 1) its prompt string is hard-coded as "Run: ", and 2) I wanted expansion of '~/' but not other special characters, so I have to manipulate the return value before passing it on to spawn. For context, I'm using this in several screenshot commands which prompt for the name of the output file. Maybe there is a better approach for prompting for directories and files both, but the existence of an XMonad.Prompt.Directory and no XMonad.Prompt.File looks to me like a simple omission. If the latter is a hack, then so is the former, but I'm not campaigning for any outcome, only offering something that I have found useful to others. Have a nice day! -- John Foerch

John J Foerch [2011.03.17 2345 -0400]: [...]
Sorry it couldn't be a more profound, creative, and interesting module :D but that's what I needed. Shell prompt does not fit the bill for two reasons: 1) its prompt string is hard-coded as "Run: ", and 2) I wanted expansion of '~/' but not other special characters, so I have to manipulate the return value before passing it on to spawn.
For context, I'm using this in several screenshot commands which prompt for the name of the output file.
Maybe there is a better approach for prompting for directories and files both, but the existence of an XMonad.Prompt.Directory and no XMonad.Prompt.File looks to me like a simple omission. If the latter is a hack, then so is the former, but I'm not campaigning for any outcome, only offering something that I have found useful to others.
I agree with you on the level that it is odd that there should be a module that handles directories but cannot do the same for files and, what's worse, has a name that clearly states it deals only with directories, making my suggestion (1) below a bit suboptimal. However, the issue of whether this functionality is already offered by another module aside, there are still two fairly clean ways of including this functionality for files without the cutting and pasting: (1) Simply add the functionality you need to X.P.Directory, factoring the code common to both handling directories and files. (2) Move all the code for directories and files to X.P.File, again properly factoring it to avoid code duplication. Then rewrite the existing X.P.Directory as a thin wrapper that imports X.P.File and reexports the directory-specific functions. The second part of this solution is to not break configurations that currently use X.P.Directory. I think (2) is preferable over (1) because "Directory" suggests that this module can deal with directories but not with files, while in my experience, modules named File-something usually deal with different types of files, including directories. Cheers, Norbert

Norbert Zeh
John J Foerch [2011.03.17 2345 -0400]:
[...]
Sorry it couldn't be a more profound, creative, and interesting module :D but that's what I needed. Shell prompt does not fit the bill for two reasons: 1) its prompt string is hard-coded as "Run: ", and 2) I wanted expansion of '~/' but not other special characters, so I have to manipulate the return value before passing it on to spawn.
For context, I'm using this in several screenshot commands which prompt for the name of the output file.
Maybe there is a better approach for prompting for directories and files both, but the existence of an XMonad.Prompt.Directory and no XMonad.Prompt.File looks to me like a simple omission. If the latter is a hack, then so is the former, but I'm not campaigning for any outcome, only offering something that I have found useful to others.
I agree with you on the level that it is odd that there should be a module that handles directories but cannot do the same for files and, what's worse, has a name that clearly states it deals only with directories, making my suggestion (1) below a bit suboptimal.
However, the issue of whether this functionality is already offered by another module aside, there are still two fairly clean ways of including this functionality for files without the cutting and pasting:
(1) Simply add the functionality you need to X.P.Directory, factoring the code common to both handling directories and files.
(2) Move all the code for directories and files to X.P.File, again properly factoring it to avoid code duplication. Then rewrite the existing X.P.Directory as a thin wrapper that imports X.P.File and reexports the directory-specific functions. The second part of this solution is to not break configurations that currently use X.P.Directory.
I think (2) is preferable over (1) because "Directory" suggests that this module can deal with directories but not with files, while in my experience, modules named File-something usually deal with different types of files, including directories.
Proposal 2 sounds like the best way to achieve a single module that handles prompting for any type of file or directory without cluttering contrib with more specialized and redundant prompt modules. I will be glad to implement it if contrib maintainers are favorable. Thanks. -- John Foerch

On Fri, Mar 18, 2011 at 1:47 PM, John J Foerch
I will be glad to implement it if contrib maintainers are favorable.
I'd be willing to commit such a generalized module*. (Although I'm not entirely keen on having 2 modules. Directories *are* files, after all.) * once I can commit anything. I try to push a doc patch to XMC every few days, and it has yet to succeed. -- gwern http://www.gwern.net

Gwern Branwen [2011.03.19 2156 -0400]:
(Although I'm not entirely keen on having 2 modules. Directories *are* files, after all.)
I agree. I personally wouldn't have any objections to scrapping X.M.Directory altogether, but I made the suggestion of keeping X.M.Directory as a thin wrapper because the xmonad community has had a (much appreciated) very strong focus on not breaking existing configs unless absolutely unavoidable. Cheers, Norbert
participants (4)
-
Brandon S Allbery KF8NH
-
Gwern Branwen
-
John J Foerch
-
Norbert Zeh