mirror of
https://github.com/arl/gitmux.git
synced 2026-09-10 07:26:18 -04:00
Issue 82/comment default config (#87)
* Remove _ prefix to variables * Update README.md: align with default config * -printcfg shows commented configuration * Remove unused formater.go * Move config-related in config.go * tmux: remove DefaultCfg variable The default configuration is now defined in an embedded file with comments. Fixes #82
This commit is contained in:
parent
4decaa8885
commit
595c9fde2f
81
.gitmux.yml
Normal file
81
.gitmux.yml
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
tmux:
|
||||
# The symbols section defines the symbols printed before specific elements
|
||||
# of Git status displayed in tmux status string.
|
||||
symbols:
|
||||
# current branch name.
|
||||
branch: "⎇ "
|
||||
# Git SHA1 hash (in 'detached' state).
|
||||
hashprefix: ":"
|
||||
# 'ahead count' when local and remote branch diverged.
|
||||
ahead: ↑·
|
||||
# 'behind count' when local and remote branch diverged.
|
||||
behind: ↓·
|
||||
# count of files in the staging area.
|
||||
staged: "● "
|
||||
# count of files in conflicts.
|
||||
conflict: "✖ "
|
||||
# count of modified files.
|
||||
modified: "✚ "
|
||||
# count of untracked files.
|
||||
untracked: "… "
|
||||
# count of stash entries.
|
||||
stashed: "⚑ "
|
||||
# count of inserted lines (stats section).
|
||||
insertions: Σ
|
||||
# count of deleted lines (stats section).
|
||||
deletions: Δ
|
||||
# Shown when the working tree is clean.
|
||||
clean: ✔
|
||||
|
||||
# Styles are tmux format strings used to specify text colors and attributes
|
||||
# of Git status elements. See the STYLES section of tmux man page.
|
||||
# https://man7.org/linux/man-pages/man1/tmux.1.html#STYLES.
|
||||
styles:
|
||||
# Clear previous style.
|
||||
clear: "#[fg=default]"
|
||||
# Special tree state strings such as [rebase], [merge], etc.
|
||||
state: "#[fg=red,bold]"
|
||||
# Local branch name
|
||||
branch: "#[fg=white,bold]"
|
||||
# Remote branch name
|
||||
remote: "#[fg=cyan]"
|
||||
# 'divergence' counts
|
||||
divergence: "#[fg=yellow]"
|
||||
# 'staged' count
|
||||
staged: "#[fg=green,bold]"
|
||||
# 'conflicts' count
|
||||
conflict: "#[fg=red,bold]"
|
||||
# 'modified' count
|
||||
modified: "#[fg=red,bold]"
|
||||
# 'untracked' count
|
||||
untracked: "#[fg=magenta,bold]"
|
||||
# 'stash' count
|
||||
stashed: "#[fg=cyan,bold]"
|
||||
# 'insertions' count
|
||||
insertions: "#[fg=green]"
|
||||
# 'deletions' count
|
||||
deletions: "#[fg=red]"
|
||||
# 'clean' symbol
|
||||
clean: "#[fg=green,bold]"
|
||||
|
||||
# The layout section defines what components gitmux shows and the order in
|
||||
# which they appear on tmux status bar.
|
||||
#
|
||||
# Allowed components:
|
||||
# - branch: local branch name. Examples: `⎇ main`, `⎇ :345e7a0` or `[rebase]`
|
||||
# - remote-branch: remote branch name, for example: `origin/main`.
|
||||
# - divergence: divergence between local and remote branch, if any. Example: `↓·2↑·1`
|
||||
# - remote: alias for `remote-branch` followed by `divergence`, for example: `origin/main ↓·2↑·1`
|
||||
# - flags: symbols representing the working tree state, for example `✚ 1 ⚑ 1 … 2`
|
||||
# - stats: insertions/deletions (lines), for example`Σ56 Δ21`
|
||||
# - some string `foo`: any other character of string is directly shown, for example `foo` or `|`
|
||||
layout: [branch, " ", remote-branch, divergence, " - ", flags]
|
||||
|
||||
# Additional configuration options.
|
||||
options:
|
||||
# Maximum displayed length for local and remote branch names.
|
||||
branch_max_len: 0
|
||||
# Trim left or right end of the branch (`right` or `left`).
|
||||
branch_trim: right
|
||||
# Character indicating whether and where a branch was truncated.
|
||||
ellipsis: …
|
||||
72
README.md
72
README.md
|
|
@ -156,51 +156,54 @@ In `tmux` status bar, `gitmux` output immediately reflects the changes you make
|
|||
|
||||
### Symbols
|
||||
|
||||
The `symbols` section describes the symbols `gitmux` prints for the various components of the status string.
|
||||
The `symbols` section defines the symbols printed before specific elements
|
||||
of Git status displayed in `tmux` status string:
|
||||
|
||||
```yaml
|
||||
symbols:
|
||||
branch: '⎇ ' # Shown before a branch
|
||||
hashprefix: ':' # Shown before a Git hash (in 'detached HEAD' state)
|
||||
ahead: ↑· # Shown before the 'ahead count' when local and remote branch diverge
|
||||
behind: ↓· # Shown before the 'behind count' when local/remote branch diverge
|
||||
staged: '● ' # Shown before the 'staged' files count
|
||||
conflict: '✖ ' # Shown before the 'conflicts' count
|
||||
modified: '✚ ' # Shown before the 'modified' files count
|
||||
untracked: '… ' # Shown before the 'untracked' files count
|
||||
stashed: '⚑ ' # Shown before the 'stash' count
|
||||
insertions: Σ # Shown before the count of insertied lines (stats sections).
|
||||
deletions: Δ # Shown before the count of deletions lines (stats sections).
|
||||
clean: ✔ # Shown when the working tree is clean (empty staging area)
|
||||
branch: "⎇ " # current branch name.
|
||||
hashprefix: ":" # Git SHA1 hash (in 'detached' state).
|
||||
ahead: ↑· # 'ahead count' when local and remote branch diverged.
|
||||
behind: ↓· # 'behind count' when local and remote branch diverged.
|
||||
staged: "● " # count of files in the staging area.
|
||||
conflict: "✖ " # count of files in conflicts.
|
||||
modified: "✚ " # count of modified files.
|
||||
untracked: "… " # count of untracked files.
|
||||
stashed: "⚑ " # count of stash entries.
|
||||
insertions: Σ # count of inserted lines (stats section).
|
||||
deletions: Δ # count of deleted lines (stats section).
|
||||
clean: ✔ # Shown when the working tree is clean.
|
||||
```
|
||||
|
||||
|
||||
### Styles
|
||||
|
||||
Styles are tmux format strings used to specify text colors and attributes.
|
||||
See [`tmux` styles reference](https://man7.org/linux/man-pages/man1/tmux.1.html#STYLES).
|
||||
Styles are tmux format strings used to specify text colors and attributes of Git
|
||||
status elements.
|
||||
See the [`STYLES` section](https://man7.org/linux/man-pages/man1/tmux.1.html#STYLES) of `tmux` man page.
|
||||
|
||||
```yaml
|
||||
styles:
|
||||
clear: '#[fg=default]' # Style clearing previous styles (printed before each component)
|
||||
state: '#[fg=red,bold]' # Style of the special states strings like [rebase], [merge], etc.
|
||||
branch: '#[fg=white,bold]' # Style of the local branch name
|
||||
remote: '#[fg=cyan]' # Style of the remote branch name
|
||||
divergence: "#[fg=yellow]" # Style of the 'divergence' string
|
||||
staged: '#[fg=green,bold]' # Style of the 'staged' files count
|
||||
conflict: '#[fg=red,bold]' # Style of the 'conflicts' count
|
||||
modified: '#[fg=red,bold]' # Style of the 'modified' files count
|
||||
untracked: '#[fg=magenta,bold]' # Style of the 'modified' files count
|
||||
stashed: '#[fg=cyan,bold]' # Style of the 'stash' entries count
|
||||
insertions: '#[fg=green]' # Style of the 'inserted lines' count
|
||||
deletions: '#[fg=red]' # Style of the 'deleted lines' count
|
||||
clean: '#[fg=green,bold]' # Style of the 'clean' symbol
|
||||
clear: '#[fg=default]' # Clear previous style.
|
||||
state: '#[fg=red,bold]' # Special tree state strings such as [rebase], [merge], etc.
|
||||
branch: '#[fg=white,bold]' # Local branch name
|
||||
remote: '#[fg=cyan]' # Remote branch name
|
||||
divergence: "#[fg=yellow]" # 'divergence' counts
|
||||
staged: '#[fg=green,bold]' # 'staged' count
|
||||
conflict: '#[fg=red,bold]' # 'conflicts' count
|
||||
modified: '#[fg=red,bold]' # 'modified' count
|
||||
untracked: '#[fg=magenta,bold]' # 'untracked' count
|
||||
stashed: '#[fg=cyan,bold]' # 'stash' count
|
||||
insertions: '#[fg=green]' # 'insertions' count
|
||||
deletions: '#[fg=red]' # 'deletions' count
|
||||
clean: '#[fg=green,bold]' # 'clean' symbol
|
||||
```
|
||||
|
||||
### Layout components
|
||||
|
||||
The layout is a list of the components `gitmux` shows, and the order in
|
||||
which they appear on `tmux` status bar.
|
||||
The `layout` section defines what components `gitmux` shows and the order in which
|
||||
they appear on `tmux` status bar.
|
||||
|
||||
|
||||
For example, the default `gitmux` layout shows is:
|
||||
|
||||
|
|
@ -223,18 +226,17 @@ the remote branch, etc.
|
|||
But you can anyway choose to never show some components if you wish, or to present
|
||||
them in a different order.
|
||||
|
||||
This is the list of the possible components of the `layout`:
|
||||
This is the list of the possible keywords for `layout`:
|
||||
|
||||
| Layout component | Description | Example |
|
||||
| Layout keywords | Description | Example |
|
||||
| :--------------: | :------------------------------------------------- | :------------------: |
|
||||
| `branch` | local branch name | `main` |
|
||||
| `remote-branch` | remote branch name | `origin/main` |
|
||||
| `divergence` | divergence local/remote branch, if any | `↓·2↑·1` |
|
||||
| `remote` | alias for `remote-branch` followed by `divergence` | `origin/main ↓·2↑·1` |
|
||||
| `flags` | Symbols representing the working tree state | `✚ 1 ⚑ 1 … 2` |
|
||||
| `stats` | Insertions/deletions (lines). Disabled by deafult | `Σ56 Δ21` |
|
||||
| any string `foo` | Any other string is directly shown | `foo` |
|
||||
|
||||
| `stats` | Insertions/deletions (lines). Disabled by default | `Σ56 Δ21` |
|
||||
| any string `foo` | Non-keywords are shown as-is | `hello gitmux` |
|
||||
|
||||
|
||||
Some example layouts:
|
||||
|
|
|
|||
24
config.go
Normal file
24
config.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
|
||||
"github.com/arl/gitmux/tmux"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// Config configures output formatting.
|
||||
type Config struct{ Tmux tmux.Config }
|
||||
|
||||
// default config (decoded in init)
|
||||
var defaultCfg Config
|
||||
|
||||
//go:embed .gitmux.yml
|
||||
var cfgBytes []byte
|
||||
|
||||
func init() {
|
||||
if err := yaml.Unmarshal(cfgBytes, &defaultCfg); err != nil {
|
||||
panic(fmt.Sprintf("default config is invalid: %v", err))
|
||||
}
|
||||
}
|
||||
13
formater.go
13
formater.go
|
|
@ -1,13 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/arl/gitstatus"
|
||||
)
|
||||
|
||||
// A formater writes the status of a Git working tree in a given format.
|
||||
type formater interface {
|
||||
// Format writes the representation of a git status.
|
||||
Format(io.Writer, *gitstatus.Status) error
|
||||
}
|
||||
11
gitmux.go
11
gitmux.go
|
|
@ -30,11 +30,6 @@ Options:
|
|||
-V prints gitmux version and exits.
|
||||
`
|
||||
|
||||
// Config configures output formatting.
|
||||
type Config struct{ Tmux tmux.Config }
|
||||
|
||||
var _defaultCfg = Config{Tmux: tmux.DefaultCfg}
|
||||
|
||||
func parseOptions() (ctx context.Context, cancel func(), dir string, dbg bool, cfg Config) {
|
||||
var (
|
||||
dbgOpt = flag.Bool("dbg", false, "")
|
||||
|
|
@ -60,13 +55,11 @@ func parseOptions() (ctx context.Context, cancel func(), dir string, dbg bool, c
|
|||
}
|
||||
|
||||
if *printCfgOpt {
|
||||
enc := yaml.NewEncoder(os.Stdout)
|
||||
check(enc.Encode(&_defaultCfg), *dbgOpt)
|
||||
enc.Close()
|
||||
os.Stdout.Write(cfgBytes)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
cfg = _defaultCfg
|
||||
cfg = defaultCfg
|
||||
|
||||
if *cfgOpt != "" {
|
||||
f, err := os.Open(*cfgOpt)
|
||||
|
|
|
|||
|
|
@ -91,45 +91,6 @@ type options struct {
|
|||
Ellipsis string `yaml:"ellipsis"`
|
||||
}
|
||||
|
||||
// DefaultCfg is the default tmux configuration.
|
||||
var DefaultCfg = Config{
|
||||
Symbols: symbols{
|
||||
Branch: "⎇ ",
|
||||
Staged: "● ",
|
||||
Conflict: "✖ ",
|
||||
Modified: "✚ ",
|
||||
Untracked: "… ",
|
||||
Stashed: "⚑ ",
|
||||
Clean: "✔",
|
||||
Ahead: "↑·",
|
||||
Behind: "↓·",
|
||||
HashPrefix: ":",
|
||||
Insertions: "Σ",
|
||||
Deletions: "Δ",
|
||||
},
|
||||
Styles: styles{
|
||||
Clear: "#[fg=default]",
|
||||
State: "#[fg=red,bold]",
|
||||
Branch: "#[fg=white,bold]",
|
||||
Remote: "#[fg=cyan]",
|
||||
Divergence: "#[fg=default]",
|
||||
Staged: "#[fg=green,bold]",
|
||||
Conflict: "#[fg=red,bold]",
|
||||
Modified: "#[fg=red,bold]",
|
||||
Untracked: "#[fg=magenta,bold]",
|
||||
Stashed: "#[fg=cyan,bold]",
|
||||
Clean: "#[fg=green,bold]",
|
||||
Insertions: "#[fg=green]",
|
||||
Deletions: "#[fg=red]",
|
||||
},
|
||||
Layout: []string{"branch", " ", "remote-branch", "divergence", " - ", "flags"},
|
||||
Options: options{
|
||||
BranchMaxLen: 0,
|
||||
BranchTrim: dirRight,
|
||||
Ellipsis: "…",
|
||||
},
|
||||
}
|
||||
|
||||
// A Formater formats git status to a tmux style string.
|
||||
type Formater struct {
|
||||
Config
|
||||
|
|
|
|||
Loading…
Reference in a new issue