ランチャー...もどき

ぬぅ...firefoxってCtrl-Cで死ぬんやね。
エントリ確認画面でころしてもうた...

あまりにソースがひどいのでアレかな?とは思ったけどまぁ、載せてみた。

ということでランチャもどき。
いちおうスキップマッチングする...よ?
っていうかスキップマッチングって結構実装楽ね。
ってことでソース

import System.Process
import System.IO
import List

skipmatch :: String -> String -> Bool
skipmatch [] _ =		False
skipmatch needle haystack =	skipmatch' needle haystack
				where	skipmatch' [] _ =			True
					skipmatch' _ [] =			False
					skipmatch' (x:xs) (y:ys) | x == y =	skipmatch' xs ys
					                         | otherwise =	skipmatch' (x:xs) ys

rotate :: Int -> [a] -> [a]
rotate n xs =	drop n xs ++ take n xs

mainloop :: [String] -> String -> Int -> IO ()
mainloop files str n =	do
			   putStr "\ESC[2J\ESC[0;0H"
			   putStr "> "
			   putStr $ unlines $ take 10 $ rotate n $ filter (skipmatch str) files
			   putStr "There are "
			   putStr $ show (length $ filter (skipmatch str) files)
			   putStrLn " possibilities"
			   putStr str
			   hFlush stdout
			   char <- getChar
			   case char of
			     '\ESC'	->	do if null $ filter (skipmatch str) files
			     			     then mainloop files "" 0
			     			     else do '[' <- getChar
			     			             char2 <- getChar
						             case char2 of
						               'A' -> mainloop files str ((n - 1) `mod` (length $ filter (skipmatch str) files))
						               'B' -> mainloop files str ((n + 1) `mod` (length $ filter (skipmatch str) files))
			     '\EOT'	->	mainloop files "" 0
			     '\DEL'	->	if str == ""
						  then mainloop files "" 0
						  else mainloop files (init str) n
			     '\n'	->	if null $ filter (skipmatch str) files
						   then	mainloop files "" 0
						   else	do runCommand $ head $ rotate n $ filter (skipmatch str) files
							   mainloop files "" 0
			     c		->	mainloop files (str ++ [c]) n

main :: IO ()
main =	do list <- readFile "list" >>= return . lines
	   hSetBuffering stdin NoBuffering
	   mainloop list "" 0

おんなじディレクトリに"list"という名前でファイル一覧を作っておいてください。

find /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin -maxdepth 1 -type f -perm +100 > list

こんな感じで適当に作っておけばおっけー。


で、こいつを起動させると

> There are 0 possibilities

とか出るんで、適当に"ffx"とか打ってみてください。
たぶん↓こんな感じになるかなと思います。

> /usr/bin/cefspdflatex
/usr/bin/cefpdflatex
/usr/bin/mailfax.sh-postfix
/usr/bin/ntfsfix
/usr/bin/firefox
/usr/bin/cef5pdflatex
/usr/bin/git-diff-index
/usr/sbin/foomatic-fix-xml
There are 8 possibilities
ffx

スキップマッチなんで正規表現的には/.*f.*f.*x.*/にマッチします。


で、上下キーでスクロールするんで↓こんな感じでfirefoxに">"を合わせてHit Enter!!

> /usr/bin/firefox
/usr/bin/cef5pdflatex
/usr/bin/git-diff-index
/usr/sbin/foomatic-fix-xml
/usr/bin/cefspdflatex
/usr/bin/cefpdflatex
/usr/bin/mailfax.sh-postfix
/usr/bin/ntfsfix
There are 8 possibilities
ffx

これでfirefoxが起動するはず。


あ、firefox多重起動しないか。
konsoleとかなんかで試してみてくださいな。


あとはUIくっつけて、一回起動したものを上にもってくるとか、履歴作るとかして、やると完成かな?
UIは...
wxとかGLとか?
わかんねぇや。まぁ、どうにかなるべ。
まだまだ実用とは程遠いけど...(д


イメージ的にはWindowsで愛用しているfenrirってソフト。
シンプルで気に入ってますv


めざせQuickSilver!?