Skip to content

Commit

Permalink
Single line prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
apauley committed Jul 26, 2016
1 parent 549bc37 commit 547f3dc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
15 changes: 1 addition & 14 deletions README.md
Expand Up @@ -22,8 +22,6 @@ Have a look at the options:
ps1 --help
```

### The default Multi-line Prompt

Put something like this in your `~/.bashrc`:

```bash
Expand All @@ -34,15 +32,4 @@ GITPS1='$(ps1 ml --track-branch=origin/master)'
PS1="${GITPS1}\n${PURPLE}\h${RESET}:${BLUE}\w${RESET}$ "
```

### Build your own prompt

This creates a simple single-line prompt:

```bash
PURPLE="\[\033[01;35m\]"
BLUE="\[\033[01;34m\]"
RESET="\[\033[00m\]"
GITPS1='$(ps1 br)'
PS1="${GITPS1} ${PURPLE}\h${RESET}:${BLUE}\w${RESET}$ "
```

Change `ml` to `sl` for a single-line prompt
16 changes: 8 additions & 8 deletions app/Main.hs
Expand Up @@ -4,22 +4,22 @@ module Main where

import Turtle
import Prelude hiding (FilePath)
import PromptLib (multiLinePrompt, colouredBranch)
import PromptLib (multiLinePrompt, singleLinePrompt)
import HSHLib (noArgs)

data PromptCommand = MultiLine (Maybe Text) | Branch (Maybe Text) deriving (Show)
data PromptCommand = MultiLine (Maybe Text) | OneLine (Maybe Text) deriving (Show)

main :: IO ()
main = do
x <- options "Git-aware prompt: https://github.com/apauley/ps1#readme" parser
case x of
MultiLine trackBranch -> multiLinePrompt trackBranch >>= echo
Branch _ -> colouredBranch >>= echo
MultiLine trackBranch -> multiLinePrompt trackBranch >>= echo
OneLine trackBranch -> singleLinePrompt trackBranch >>= echo

parser :: Parser PromptCommand
parser = fmap MultiLine (subcommand "ml" "Generates a multi-line git-aware shell prompt" mlParser)
<|> fmap Branch (subcommand "br" "Returns a coloured branch name" noArgs)
parser = fmap MultiLine (subcommand "ml" "Generates a multi-line git-aware shell prompt" trackParser)
<|> fmap OneLine (subcommand "sl" "Generates a single-line git-aware shell prompt" trackParser)

mlParser :: Parser (Maybe Text)
mlParser = optional (optText "track-branch" 't'
trackParser :: Parser (Maybe Text)
trackParser = optional (optText "track-branch" 't'
"Track if your commits are directly on top of a branch that you may need to merge back to, eg. origin/master")
6 changes: 3 additions & 3 deletions src/PromptLib.hs
@@ -1,7 +1,7 @@
{-# LANGUAGE OverloadedStrings #-}

module PromptLib (multiLinePrompt
,colouredBranch) where
,singleLinePrompt) where

import Turtle
import Prelude hiding (FilePath)
Expand All @@ -23,8 +23,8 @@ multiLinePrompt trackBranch = do
gitLines <- getGitLines br trackBranch st
return $ format (s%"\n"%s) timeLine gitLines

colouredBranch :: IO Text
colouredBranch = do
singleLinePrompt :: Maybe Text -> IO Text
singleLinePrompt trackBranch = do
br <- currentBranchDiscardErr
st <- shortStatus
return $ colourBranch br st
Expand Down

0 comments on commit 547f3dc

Please sign in to comment.