Skip to content

Make all positional parameters available as special vars #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions hs/Language/Bash/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Data.Word (Word8)
import Data.ByteString.Char8
import Data.Foldable hiding (all, any, elem)
import Data.Monoid
import Numeric.Natural (Natural)

import qualified Text.ShellEscape as Esc

Expand Down Expand Up @@ -320,6 +321,7 @@ data SpecialVar
| DollarBang | DollarUnderscore
| Dollar0 | Dollar1 | Dollar2 | Dollar3 | Dollar4
| Dollar5 | Dollar6 | Dollar7 | Dollar8 | Dollar9
| DollarNat Natural
deriving instance Eq SpecialVar
deriving instance Ord SpecialVar
deriving instance Show SpecialVar
Expand Down Expand Up @@ -347,21 +349,25 @@ specialVar b | "$?" == b = Just DollarQuestion
| otherwise = Nothing

specialVarBytes :: SpecialVar -> ByteString
specialVarBytes DollarQuestion = "$?"
specialVarBytes DollarHyphen = "$-"
specialVarBytes DollarDollar = "$$"
specialVarBytes DollarBang = "$!"
specialVarBytes DollarQuestion = "$?"
specialVarBytes DollarHyphen = "$-"
specialVarBytes DollarDollar = "$$"
specialVarBytes DollarBang = "$!"
specialVarBytes DollarUnderscore = "$_"
specialVarBytes Dollar0 = "$0"
specialVarBytes Dollar1 = "$1"
specialVarBytes Dollar2 = "$2"
specialVarBytes Dollar3 = "$3"
specialVarBytes Dollar4 = "$4"
specialVarBytes Dollar5 = "$5"
specialVarBytes Dollar6 = "$6"
specialVarBytes Dollar7 = "$7"
specialVarBytes Dollar8 = "$8"
specialVarBytes Dollar9 = "$9"
specialVarBytes Dollar0 = "$0"
specialVarBytes Dollar1 = "$1"
specialVarBytes Dollar2 = "$2"
specialVarBytes Dollar3 = "$3"
specialVarBytes Dollar4 = "$4"
specialVarBytes Dollar5 = "$5"
specialVarBytes Dollar6 = "$6"
specialVarBytes Dollar7 = "$7"
specialVarBytes Dollar8 = "$8"
specialVarBytes Dollar9 = "$9"
specialVarBytes (DollarNat i) = if i <= 9 then
"$" <> (pack $ show i)
else
"${" <> (pack $ show i) <> "}"


data Trim = ShortestLeading | LongestLeading
Expand Down Expand Up @@ -457,4 +463,3 @@ instance Foldable Assignment where
where
f' = foldMap f
foldMapPair (x, y) = f' x `mappend` f' y

2 changes: 1 addition & 1 deletion hs/bash.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ library
Language.Bash.PrettyPrinter.State
Language.Bash.Annotations
Language.Bash.Lib

ghc-options : -Wincomplete-patterns -Werror