Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

move (trifling) scripts to separate package

  • Loading branch information...
commit ad974ca8830ec574e35a06f0012b198be9179456 1 parent e374200
@dancor dancor authored
View
15 FUtil.cabal
@@ -4,20 +4,9 @@ synopsis: generic utility library and scripts useful for many projects
license: GPL
license-file: LICENSE
author: futil@lists.facebook.com
+build-type: Simple
build-depends: HSH >= 2, MonadRandom, array, base, bytestring, containers,
haskell98, mtl, process, random, time
+
exposed-modules: FUtil
hs-source-dirs: src
-build-type: Simple
-
-executable: align
-main-is: align.hs
-hs-source-dirs: src
-
-executable: sorth
-main-is: sorth.hs
-hs-source-dirs: src
-
-executable: wordSwap
-main-is: wordSwap.hs
-hs-source-dirs: src
View
132 bin/hsb
@@ -1,132 +0,0 @@
-#!/usr/bin/env python
-#
-# haskell build/etc wrapper for cabal or non-cabal (ghc with obj/ dir)
-# - note this has very little (but non-zero still) use now that cabal-install
-# exists
-#
-#
-# cabal is more standard for packaging
-# non-cabal is faster for development work on an executable (non-library)
-#
-# non-cabal mode can read a 'name' file for the name of your executable which
-# is produced from src/<name>.hs. it will assume name = 'Main' otherwise
-
-from optparse import OptionParser
-import cmd_util as cu
-import os
-import sys
-
-usage = """usage: %prog [options] [-- <args for run, or configure, or build>]
-
-configure/build/install your program with cabal (by default)
-or build/run program or test suite with ghc
-(assuming src/ structure and other things)"""
-p = OptionParser(usage)
-# todo: support clean for gen?, support test for cabal
-# fixme: too many non-obviousities,
-# like that optimize with cabal only applies to configure?
-# or should you know that (we could at least warn)
-p.add_option('-b', '--build', action='store_true')
-p.add_option('-c', '--configure', action='store_true')
-p.add_option('-C', '--cabal', action='store_true')
-#p.add_option('-H', '--haddock', action='store_true')
-p.add_option('-k', '--clean', action='store_true')
-p.add_option('-i', '--install', action='store_true')
-p.add_option('-O', '--optimize', action='store_true')
-p.add_option('-2', '--optimize2', action='store_true')
-p.add_option('-r', '--run', action='store_true')
-p.add_option('-t', '--test', action='store_true')
-(opts, args) = p.parse_args()
-
-#steps_poss = ['clean', 'configure', 'build', 'install', 'run', 'haddock']
-steps_poss = ['clean', 'configure', 'build', 'install', 'run']
-steps = []
-for step in steps_poss:
- if getattr(opts, step):
- steps.append(step)
-if not steps:
- if opts.test:
- # common case for test is to build the test then run the test
- steps = ['build', 'run']
- else:
- # in most common case we just want to install some normal cabal package
- steps = ['configure', 'build', 'install']
- opts.cabal = True
- if not opts.optimize:
- # this if is so that 'hsb -O' works as expected (and not as
- # 'hsb -2' which is the default); no reason not to support that
- opts.optimize2 = True
-
-if opts.cabal:
- if opts.test:
- cu.error_out('testing thru cabal not supported')
-
- setup = 'Setup.lhs'
- if not os.path.exists(setup):
- setup = 'Setup.hs'
-
- for step in steps:
- if step == 'run':
- continue
- cmd = ['runhaskell', setup, step]
- if step == 'configure':
- if opts.optimize:
- cmd += ['-O']
- if opts.optimize2:
- cmd += ['--ghc-options=-O2']
- if 'run' not in steps:
- # configure is most useful step to take extra args in cabal case
- # if we aren't running
- cmd += args
- elif step == 'install':
- cmd = ['sudo'] + cmd
- cu.cmd_wait(cmd)
-else:
- if 'configure' in steps:
- cu.error_out('configuring thru non-cabal not supported')
- if opts.clean:
- cu.error_out('cleaning thru non-cabal not supported')
-
- if os.path.exists('name'):
- name = file('name').readlines()[0][:-1]
- else:
- cabal_suffix = '.cabal'
- cabal_files = \
- [f for f in os.listdir(os.curdir) if f.endswith(cabal_suffix)]
- if len(cabal_files) == 1:
- name = cabal_files[0][:-len(cabal_suffix)]
- else:
- name = 'Main'
- if opts.test:
- if 'install' in steps:
- cu.error_out('installing test not supported')
-
- name += '.Check'
- if 'build' in steps:
- if not os.path.exists('obj'):
- os.mkdir('obj')
- cmd = ['ghc', '-threaded', '--make', '-odir', 'obj', '-hidir', 'obj',
- 'src/Main.hs', '-o', name]
- if opts.optimize:
- cmd += ['-O']
- if opts.optimize2:
- cmd += ['-O2']
- if 'run' not in steps:
- # build is most useful step to take extra args in non-cabal case
- # if we aren't running
- cmd += args
- cu.cmd_wait(cmd)
- if 'install' in steps:
- cu.cmd_wait(['sudo', 'cp', name, '/usr/local/bin'])
-
-if 'run' in steps:
- if opts.cabal:
- name_cmd = 'grep executable *.cabal | head -n1 | awk \'{print $2}\''
- name = cu.cmd_output(name_cmd)[0]
- else:
- name = './' + name
- print >> sys.stdout, 'running'
- cu.cmd_wait([name] + args)
-
-#if 'haddock' in steps:
-#
View
3  bin/hsg
@@ -1,3 +0,0 @@
-#!/bin/sh
-# grep thru haskell code
-find . -path ./_darcs -prune -o -name '*.*hs' -print | xargs grep -nH "$@"
View
8 bin/hst
@@ -1,8 +0,0 @@
-#!/bin/sh
-# generate haskell ctags
-find . -path ./_darcs -prune -o -name '*.*hs' -print | xargs hasktags -c &&
-# hasktags does not sort the tags
-# also, sort (for all its options) cannot seem to be made to sort them
-# correctly! (i.e. simple ascii sort..)
-# but sorth does (simple ascii sort written in haskell)
-inPl tags sorth >/dev/null
View
13 bin/killQual
@@ -1,13 +0,0 @@
-#!/bin/sh
-#
-# ~ killQual MyLol someFile.hs
-# will convert from:
-# import qualified Lol as MyLol
-# MyLol.yay
-# to:
-# import Lol
-# yay
-
-Q="$1"
-F="$2"
-inPl "$F" sed 's/qualified \([^ ]*\) \bas '"$Q"'\b/\1/;s/'"$Q"'\.//g'
View
1  install
@@ -1,4 +1,3 @@
#!/bin/sh
set -e
cabal install --enable-optimization=2 --global --root-cmd=sudo
-sudo cp bin/* /usr/local/bin
View
28 src/FUtil.Check.hs
@@ -1,28 +0,0 @@
-module Main where
-
-import Data.Char
-import Data.List
-import Test.QuickCheck
-import FUtil
-
-instance Arbitrary Char where
- arbitrary = choose ('a', 'b')
- coarbitrary c = variant (ord c `rem` 4)
-
-chkInterBreaks :: Char -> [Char] -> Bool
-chkInterBreaks c s = intercalate [c] (breaks (== c) s) == s
-
-chkCalate :: [Char] -> [Char] -> Bool
-chkCalate glue s = s == intercalate glue (uncalate glue s)
-
-{-
-chks = [chkInterBreaks, chkDblTransp]
--}
-
---chkF = quickCheck
---chkF = verboseCheck
-
-main = do
- -- todo: TH to at least get chkF..
- quickCheck chkInterBreaks
- verboseCheck chkCalate
View
40 src/align.hs
@@ -1,40 +0,0 @@
--- align code to stdin based on args
--- usage: align <string-to-align-at> [on-nth-incidence-of-string]
-
-import System.Environment
-import FUtil
-
--- perform a "break-like" function at the nth place instead of the first place
-breaklikeNth :: Int -> [a] -> ([a] -> Maybe ([a], [a])) -> [a] ->
- Maybe ([a], [a])
-breaklikeNth 1 _ f xs = f xs
-breaklikeNth n glue f xs = do
- (l, r) <- breaklikeNth (n - 1) glue f xs
- (rl, rr) <- f r
- return (l ++ glue ++ rl, rr)
-
--- take a non-hacky break-like function: returning Maybe (l, r)
--- and make it hacky like break is: returning (l, glue ++ r)
-breaklikeHack :: [a] -> ([a] -> Maybe ([a], [a])) -> [a] -> ([a], [a])
-breaklikeHack glue f xs = case f xs of
- Nothing -> (xs, [])
- Just (l, r) -> (l, glue ++ r)
-
-breakOnNthSublHacky :: Eq a => Int -> [a] -> [a] -> ([a], [a])
-breakOnNthSublHacky n s = breaklikeHack s (breaklikeNth n s (breakOnSubl s))
-
-alignOn :: Int -> String -> [String] -> [String]
-alignOn n s ls = map unbreak (zip (spaceBlock p1) p2) where
- (p1, p2) = unzip (map (breakOnNthSublHacky n s) ls)
- unbreak (a, b) = a ++ b
-
-main = do
- as <- getArgs
- let
- argN = length as
- n = if argN == 1 then Just 1 else if argN == 2
- then Just $ read $ as !! 1
- else Nothing
- case n of
- Nothing -> putStrLn "usage"
- Just n -> interactL $ alignOn n (head as)
View
3  src/sorth.hs
@@ -1,3 +0,0 @@
-import FUtil
-import Data.List
-main = interactL sort
View
30 src/wordSwap.hs
@@ -1,30 +0,0 @@
--- swap ith and jth words on every line
--- (keeping any word-trailing whitespace with the word)
--- usage: wordSwap i j
--- note that if there is leading whitespace, the first "word" is ""
-
-import Data.Array
-import Data.Char
-import System.Environment
-import System.IO
-import FUtil
-
-wordsWithWS :: String -> [String]
-wordsWithWS [] = []
-wordsWithWS s = let
- (a, b) = span (not . isSpace) s
- (b1, b2) = span isSpace b
- in (a ++ b1):wordsWithWS b2
-
-swapIndices :: Int -> Int -> [a] -> [a]
-swapIndices i j xs = elems $
- listArray (1, length xs) xs // [(i, xs !! (j - 1)), (j, xs !! (i - 1))]
-
-swapWords :: Int -> Int -> String -> String
-swapWords i j = concat . swapIndices i j . wordsWithWS
-
-main = do
- args <- getArgs
- case sequence $ map readMb args of
- Just [i, j] -> interactL $ map (swapWords i j)
- _ -> hPutStrLn stderr "usage"
Please sign in to comment.
Something went wrong with that request. Please try again.