Skip to content
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ build/
develop-eggs/
dist/
eggs/
.eggs/
lib/
lib64/
parts/
Expand All @@ -29,6 +30,7 @@ pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.pytest_cache/
.tox/
.coverage
.cache
Expand Down
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ language: python

python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.8"
- "3.9-dev"

install:
- pip install -r requirements.txt
- pip install -r test/requirements.txt
- pip install -r docs/requirements.txt
- pip install coverage
- pip install coveralls
- pip install future
- pip install mock
- pip install configparser
- pip install pytest
- pip install sphinx

script:
- git fetch
Expand Down
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ The latest version can be installed from PyPI using `pip`:
sudo pip install prompty
```

You then need to insert a line at the end of your `.bashrc` file so that prompty is called from the `PS1` environment variable:
It is a good idea to test that prompty is working correctly before continuing. Run the `prompty` command on its own and ensure that there are no errors:

```bash
prompty -b >> ~/.bashrc
prompty
```

If all has gone well, you should see some colourful output. (If not, see the tip section below for some ideas).

In order for for prompty to be integrated into your bash prompt, you need to insert a line at the end of your `.bashrc` file so that it is called from your `PS1` environment variable:

```bash
prompty gen-bashrc >> ~/.bashrc
```

Now re-source your updated `.bashrc` file:
Expand All @@ -31,11 +39,18 @@ source ~/.bashrc
```
(alternatively you can restart your shell session)

You should now see the default prompty prompt.

> **Tip:** If you get an error like "`bash: prompty: command not found`", it is probably because you installed it locally, as a non-root user (without `sudo`). This is fine, but you will need to call the prompty executable from its local path:
> **Tip:** If you get an error like "`prompty: command not found`", it is probably because you installed it locally as a non-root user (without `sudo`). This is fine, but you will need to call the prompty executable from its local path. The previous commands can be replaced with:
>
> `~/.local/bin/prompty -b >> ~/.bashrc`

> `# Test that prompty works`
> `~/.local/bin/prompty`
>
> `# Update .bashrc file`
> `~/.local/bin/prompty bashrc >> ~/.bashrc`
>
> `# Reload .bashrc`
> `source ~/.bashrc`

# Configuration

Expand Down
125 changes: 6 additions & 119 deletions bin/prompty
Original file line number Diff line number Diff line change
Expand Up @@ -3,138 +3,25 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import datetime
START = datetime.datetime.now() # noqa

# Import external modules
import sys
import os
import getopt
import codecs
import os.path

# Add base directory to path so that it can find the prompty package
sys.path[0:0] = [os.path.join(os.path.dirname(__file__), "..")] # noqa

import prompty
import prompty.cli
prompty.cli.START = START

# Overload sys.stdout to support unicode
UTF8Writer = codecs.getwriter('utf-8')
sys.stdout = UTF8Writer(sys.stdout)

USAGE = "Usage: %s [options]" % sys.argv[0] + """
Options: -h, --help Display this help message and exit
"""
def main():
prompty.cli.cli()


def usage(msg=''):
"""Print usage information to stderr.

@param msg: An optional message that will be displayed before the usage
@return: None
"""
if msg:
print(msg, file=sys.stderr)
print(USAGE, file=sys.stderr)


def main(argv=None):
"""Main function. This is the entry point for the program and is run when
the script is executed stand-alone (i.e. not included as a module

@param argv: A list of argumets that can over-rule the command line arguments.
@return: Error status
@rtype: int
"""

# Use the command line (system) arguments if none were passed to main
if argv is None:
argv = sys.argv

# Parse command line options
try:
opts, args = getopt.getopt(argv[1:], "hbcdpw:v", [
"help", "bash", "colours", "debug", "palette", "working-dir=", "version"
])
except getopt.error as msg:
usage(msg.msg)
return 1

# Defaults
debug = False
workingDir = None

# Act upon options
for option, arg in opts:
if option in ("-h", "--help"):
usage()
return 0

if option in ("-b", "--bashrc"):
abs_path = os.path.abspath(sys.argv[0])
print("export PS1=\"\\$(%s \\$?)\"" % abs_path)
return 0

if option in ("-c", "--colours"):
c = prompty.colours.Colours(prompty.functionContainer.FunctionContainer())
for style in c.STYLES:
for colour in c.COLOURS:
print("%s%s : %s%s" % (c.startColour(colour, style=style, _wrap=False),
style[c.NAME_KEY],
colour[c.NAME_KEY],
c.stopColour(_wrap=False)))
return 0

if option in ("-d", "--debug"):
debug = True

if option in ("-p", "--palette"):
c = prompty.colours.Colours(prompty.functionContainer.FunctionContainer())
for colour in c.PALETTE:
print("%s%s%s" % (
c.startColour(
fgcolour=colour[c.FG_KEY],
bgcolour=colour[c.BG_KEY],
style=colour[c.STYLE_KEY],
_wrap=False
),
colour[c.NAME_KEY],
c.stopColour(_wrap=False))
)
return 0

if option in ("-w", "--working-dir"):
workingDir = arg

if option in ("-v", "--version"):
print(prompty.__version__)
return 0

if len(args) < 1:
usage("Not enough arguments")
return 1

exitStatus = int(args[0])

s = prompty.status.Status(exitStatus, workingDir)

p = prompty.prompt.Prompt(s)

prompt = p.getPrompt()

if debug:
elapsed = datetime.datetime.now() - START
sys.stdout.write("%d\n" % (elapsed.total_seconds()*1000))

sys.stdout.write(prompt)

return exitStatus


# ---------------------------------------------------------------------------#
# End of functions #
# ---------------------------------------------------------------------------#
# Run main if this file is not imported as a module
if __name__ == "__main__":
sys.exit(main())
main()
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# The short X.Y version
version = u''
# The full version, including alpha/beta/rc tags
release = u'0.3.0'
release = u'0.4.rc1'


# -- General configuration ---------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion prompty/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:

# Must comply with http://legacy.python.org/dev/peps/pep-0440/#version-scheme
__version__ = "0.3.0"
__version__ = "0.4.rc2"


from . import prompt
from . import functions
Expand All @@ -16,3 +17,4 @@
from . import config
from . import git
from . import svn
from . import cli
Loading