hmenu (empty) → 0.1.0.1
raw patch · 4 files changed
+103/−0 lines, 4 filesdep +MissingHdep +basedep +processsetup-changed
Dependencies added: MissingH, base, process
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- hmenu.cabal +27/−0
- src/Main.hs +44/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2015, Robin Schroer++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Robin Schroer nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
@@ -0,0 +1,27 @@+-- Initial hmenu.cabal generated by cabal init. For further documentation,+-- see http://haskell.org/cabal/users-guide/++name: hmenu+version: 0.1.0.1+synopsis: CLI fuzzy finder and launcher+description: hmenu is a program launcher for the terminal inspired by+ dmenu. Contrary to dmenu, it uses fuzzy filtering to find+ the program you are looking for.+license: BSD3+license-file: LICENSE+author: Robin Schroer+maintainer: sulami@peerwire.org+-- copyright: +category: System+build-type: Simple+-- extra-source-files: +cabal-version: >=1.10++executable hmenu+ main-is: Main.hs+ -- other-modules: + -- other-extensions: + build-depends: base >=4.7 && <4.8, process >=1.2 && <1.3+ , MissingH+ hs-source-dirs: src+ default-language: Haskell2010
+ src/Main.hs view
@@ -0,0 +1,44 @@+module Main where++import Data.List (intersperse)+import System.Cmd.Utils (forkRawSystem)+import System.Environment (getArgs)+import System.Exit (exitSuccess)+import System.IO (+ hFlush, stdout, hSetBuffering, stdin, BufferMode (NoBuffering), hSetEcho+ )++import Files+import FuzzyFinder++ff :: [String] -> String -> IO ()+ff list q = do query <- getChar+ let nq = case query of+ '\x7f' -> if q == "" then q else init q -- Backspace+ '\x17' -> "" -- Ctrl-w+ '\n' -> if q == "" then "true" else q -- Enter+ _ -> q ++ [query]+ let results = case nq of+ "" -> list+ _ -> fuzzyFinder nq list+ putStr "\x1b[2K\r"+ if query == '\n'+ then do forkRawSystem (head results) []+ exitSuccess+ else return ()+ let colo = case length results of+ 0 -> "\x1b[31m"+ _ -> "\x1b[34m"+ putStr $ colo ++ nq ++ "\x1b[39m: "+ putStr $ unwords $ take 5 results+ hFlush stdout+ ff list nq++main = do path <- getPath+ list <- getExecutables path+ hSetBuffering stdin NoBuffering+ hSetEcho stdin False+ putStr $ ": " ++ unwords (take 5 list)+ hFlush stdout+ ff list ""+