ph

command module
v0.0.0-...-ef490db Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

README

Prompt Helper

Background

I am very not good at shell script. Early this year, I moved my daily development shell from zsh to fish. It took me times to move my prompt setting. So why not do it on Go. It also a good small project to learn a new language.

It looks pretty good now and works for tmux and shell.

git status clean:

git status dirty:

tmux:

Install

  1. Install golang.
  2. Install nerd fonts, I am using Hack Nerf fonts, not all fonts works good on my environment.
  3. run ./install.sh to install.
  4. (Optional) You can custom your prompt color scheme. Copy or link ph.example.conf to ~/.ph.
Setup for fish

Put ph in function fish_prompt, ph shortpath maybe useful for window title.

function fish_prompt
  set -l last_status $status
  $HOME/go/bin/ph prompt $last_status
end

function fish_title
  # short pwd
  set p ($HOME/go/bin/ph shortpath)

  # current running and OS
  if [ $_ = 'fish' ]
    if [ -n "$TMUX" ]
      printf $p
      return
    end
    printf '@%s:   %s' $OS_NAME $p
  else
    if [ -n "$TMUX" ]
      printf '%s %s' $OS_NAME $_ $p
      return
    end
    printf '@%s:   %s %s' $OS_NAME $_ $p
  end
end
Setup for zsh
# in .zshrc
export PROMPT="%(?.$(~/go/bin/ph prompt 0).$(~/go/bin/ph prompt 1))"
Setup for tmux

I put prompt info on the left and the window list on the right of status bar.

# tmux.conf

# theme
# Set the background color dark grey
set -g status-style bg=colour240

# Show nothing on status left
set -g status-left ''
set -g status-left-length 80

# Show nothing on status right
set -g status-right ''
set -g status-justify right
set -g window-status-current-style bg=colour28,bold
set -g window-status-current-format ' #[fg=colour15]#I.#W#F '
set -g window-status-format ' #[fg=colour15]#I.#W '

In fish, set status bar when receive fish_prompt event.

function set_status -e fish_prompt
  if [ ! -n "$TMUX" ]
    return
  end

  set -l tmuxstatus ($HOME/go/bin/ph tmux)
  tmux set -g status-left "$tmuxstatus" 1
end

In zsh, set status bar in precmd().

Try it now

/path/to/ph prompt 1
/path/to/ph tmux 1
/path/to/ph shortpath

Configure

ph has default config. But still allow you to customize. You only need to add the fill you want to change.

vcs:
 # want to make ph faster, tell ph to skip git.
 git_skip:
  - /not/path/for/code

# Path shortern, home already included
path_shortern:
 ^/long/path: short

# Change theme
theme:
 prompt: simpleass

scheme:
 # only change color of os field for simpleass theme
 simpleass:
  os:
   fg: 15

Integration

You can use ph as library and buid your own ph. You can build your theme and vcs support and then register it like cmd/cmd.go.

License

Apache 2.0

Documentation

Overview

Package main entry point of this tools

Directories

Path Synopsis
Package cmd helps run the app.
Package cmd helps run the app.
Package theme render the tmux status theme and prompt theme
Package theme render the tmux status theme and prompt theme
powerline
Package powerline a powerline theme for prompt
Package powerline a powerline theme for prompt
simple
Package simple contains a simple theme for prompt
Package simple contains a simple theme for prompt
simpleass
Package simpleass contains a prompt theme similar with https://github.com/oh-my-fish/oh-my-fish/blob/master/docs/Themes.md#simple-ass-prompt
Package simpleass contains a prompt theme similar with https://github.com/oh-my-fish/oh-my-fish/blob/master/docs/Themes.md#simple-ass-prompt
vcs
Package vcs stores helper for getting vcs information
Package vcs stores helper for getting vcs information
git
Package git contains vcs info for git
Package git contains vcs info for git
hg
Package hg contains vcs info for hg
Package hg contains vcs info for hg

Jump to

Keyboard shortcuts

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