psh

package module
v0.0.0-...-c6df1d4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

README

psh

Fast, configurable shell prompt.

License CircleCI Status Coverage Report Go Report Card CII Best Practices GoDoc

Installation

How to install:

$ go get -u github.com/repejota/psh
[...]

And use this on your .bash_profile

# Usage:
# $ source install.sh

function __psh {
    PS1="$(psh)"
}
export PS1="$(psh)"
PROMPT_COMMAND=__psh

Screenshot

psh screenshot

License

Copyright (c) 2018 psh project Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Index

Constants

View Source
const (
	// SegmentEnvBackgroundR ...
	SegmentEnvBackgroundR = 163

	// SegmentEnvBackgroundG ...
	SegmentEnvBackgroundG = 104

	// SegmentEnvBackgroundB ...
	SegmentEnvBackgroundB = 75
)
View Source
const (
	// SegmentGitBackground is the background color to use
	SegmentGitBackground = 148 // #afd700

	// SegmentGitBackgroundR ...
	SegmentGitBackgroundR = 160

	// SegmentGitBackgroundG ...
	SegmentGitBackgroundG = 180

	// SegmentGitBackgroundB ...
	SegmentGitBackgroundB = 117

	// SegmentGitForeground is the foreground color to use
	SegmentGitForeground = 0 // #000000
)
View Source
const (
	// SegmentVirtualEnvBackground is the background color to use
	SegmentVirtualEnvBackground = 22 // #585858

	// SegmentVirtualEnvBackgroundR ...
	SegmentVirtualEnvBackgroundR = 61

	// SegmentVirtualEnvBackgroundG ...
	SegmentVirtualEnvBackgroundG = 116

	// SegmentVirtualEnvBackgroundB ...
	SegmentVirtualEnvBackgroundB = 132
)
View Source
const (
	// DefaultSegments are tbe list of segments to show on the prompt by
	// default.
	DefaultSegments = "username,hostname,virtualenv,cwd,git,root"
)
View Source
const (
	// SegmentCWDBackground is the background color to use
	SegmentCWDBackground = 237 // #3a3a3a
)
View Source
const (
	// SegmentHostnameBackground is the background color to use
	SegmentHostnameBackground = 238 // #444444
)
View Source
const (
	// SegmentRootBackground is the background color to use
	SegmentRootBackground = 236 // #303030
)
View Source
const (
	// SegmentUsernameBackground is the background color to use
	SegmentUsernameBackground = 240 // #585858
)

Variables

This section is empty.

Functions

func ResetBackground

func ResetBackground() []byte

ResetBackground reset background to default value.

func ResetFgBg

func ResetFgBg() []byte

ResetFgBg resets foreground and background to default values.

func ResetForeground

func ResetForeground() []byte

ResetForeground reset foreground to default value.

func SetBackground

func SetBackground(background uint8) []byte

SetBackground sets background color on the terminal

func SetForeground

func SetForeground(foreground uint8) []byte

SetForeground sets foreground color on the terminal.

func SetTrueColorBackground

func SetTrueColorBackground(r, g, b int) []byte

SetTrueColorBackground sets background color on the terminal using true color format.

func SetTrueColorForeground

func SetTrueColorForeground(r, g, b int) []byte

SetTrueColorForeground sets foreground color on the terminal using true color format.

Types

type Prompt

type Prompt struct {
	// contains filtered or unexported fields
}

Prompt type that defines the shell prompt structure.

func NewPrompt

func NewPrompt(segments string) *Prompt

NewPrompt creates a new prompt and returns a pointer to its instance.

func (*Prompt) Compile

func (p *Prompt) Compile()

Compile traverses all available segments. It also process each segment to get all the data needed to render.

func (*Prompt) Render

func (p *Prompt) Render() []byte

Render compiles all the segments on the prompt and concatenates its results.

Receives the list of segments to render them in the correct order.

type Segment

type Segment interface {
	Compile()
	Render() []byte
}

Segment is a partial or portion of the final prompt.

type SegmentCWD

type SegmentCWD struct {
	Data []byte
}

SegmentCWD implements the current working directory partial of the prompt.

It renders the current working directory path.

func NewSegmentCWD

func NewSegmentCWD() *SegmentCWD

NewSegmentCWD creates an instace of SegmentCWD type.

func (*SegmentCWD) Compile

func (s *SegmentCWD) Compile()

Compile collects the data for this segment.

func (*SegmentCWD) Render

func (s *SegmentCWD) Render() []byte

Render renders the segment results.

type SegmentEnv

type SegmentEnv struct {
	Data []byte
}

SegmentEnv implements the python virtual env partial of the prompt.

Renders the current virtalenv python environment name if it is available.

func NewSegmentEnv

func NewSegmentEnv() *SegmentEnv

NewSegmentEnv creates an instace of SegmentEnv type.

func (*SegmentEnv) Compile

func (s *SegmentEnv) Compile()

Compile collects the data for this segment.

func (*SegmentEnv) Render

func (s *SegmentEnv) Render() []byte

Render renders the segment results.

type SegmentGit

type SegmentGit struct {
	Data []byte
}

SegmentGit implements the git SCM partial of the prompt.

It renders the current branch if the folder contains a repository.

TODO: * git rev-parse --show-toplevel : shows root of the repo * git status --porcelain -b : shows conmplete status of the repo

func NewSegmentGit

func NewSegmentGit() *SegmentGit

NewSegmentGit creates an instace of SegmentGit type.

func (*SegmentGit) Compile

func (s *SegmentGit) Compile()

Compile collects the data for this segment.

func (*SegmentGit) Render

func (s *SegmentGit) Render() []byte

Render renders the segment results.

type SegmentHostname

type SegmentHostname struct {
	Data []byte
}

SegmentHostname implements the hostname partial of the prompt.

It renders the current hostname up to the first '.'

TODO: * Add support for long/conmplete hostname.

func NewSegmentHostname

func NewSegmentHostname() *SegmentHostname

NewSegmentHostname creates an instace of SegmentHostname type.

func (*SegmentHostname) Compile

func (s *SegmentHostname) Compile()

Compile collects the data for this segment.

func (*SegmentHostname) Render

func (s *SegmentHostname) Render() []byte

Render renders the segment results.

type SegmentRoot

type SegmentRoot struct {
	Data []byte
}

SegmentRoot implements the root partial of the prompt.

It renders the special character string "\$". In bash this results to character '#' if the effective UID is 0, otherwise '$'.

TODO: * Change background color if the last command exit status != 0

func NewSegmentRoot

func NewSegmentRoot() *SegmentRoot

NewSegmentRoot creates an instace of SegmentRoot type.

func (*SegmentRoot) Compile

func (s *SegmentRoot) Compile()

Compile collects the data for this segment.

func (*SegmentRoot) Render

func (s *SegmentRoot) Render() []byte

Render renders the segment results.

type SegmentUnknown

type SegmentUnknown struct {
	Data []byte
}

SegmentUnknown implements the not-found segment partial of the prompt.

It renders an empty string.

func NewSegmentUnknown

func NewSegmentUnknown() *SegmentUnknown

NewSegmentUnknown creates an instace of SegmentUnknown type.

func (*SegmentUnknown) Compile

func (s *SegmentUnknown) Compile()

Compile ...

func (*SegmentUnknown) Render

func (s *SegmentUnknown) Render() []byte

Render renders the segment results.

type SegmentUsername

type SegmentUsername struct {
	Data []byte
}

SegmentUsername implements the username partial of the prompt.

Renders the current username.

TODO: * If the user is root (uid=0) use a different background.

func NewSegmentUsername

func NewSegmentUsername() *SegmentUsername

NewSegmentUsername creates an instace of SegmentUsername type.

func (*SegmentUsername) Compile

func (s *SegmentUsername) Compile()

Compile collects the data for this segment.

func (*SegmentUsername) Render

func (s *SegmentUsername) Render() []byte

Render renders the segment results.

type SegmentVirtualEnv

type SegmentVirtualEnv struct {
	Data []byte
}

SegmentVirtualEnv implements the python virtual env partial of the prompt.

Renders the current virtalenv python environment name if it is available.

func NewSegmentVirtualEnv

func NewSegmentVirtualEnv() *SegmentVirtualEnv

NewSegmentVirtualEnv creates an instace of SegmentVirtualEnv type.

func (*SegmentVirtualEnv) Compile

func (s *SegmentVirtualEnv) Compile()

Compile collects the data for this segment.

func (*SegmentVirtualEnv) Render

func (s *SegmentVirtualEnv) Render() []byte

Render renders the segment results.

Directories

Path Synopsis
cmd
psh

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL