Skip to content

Commit 75b40ee

Browse files
committed
Add support for style overrides
1 parent 0fbde34 commit 75b40ee

File tree

4 files changed

+639
-217
lines changed

4 files changed

+639
-217
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2018-2019 Samuel Laurén
1+
Copyright 2018-2020 Samuel Laurén
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy of
44
this software and associated documentation files (the "Software"), to deal in

README.md

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,35 @@ make
3434
### Usage
3535

3636
```
37-
Usage: rainbowpath [-p PALETTE] [-s STYLE] [-S SEPARATOR] [-m METHOD]
37+
Usage: rainbowpath [-p PALETTE] [-s PALETTE] [-S SEPARATOR] [-m METHOD]
38+
[-M METHOD] [-o INDEX STYLE] [-O INDEX STYLE]
3839
[-l] [-c] [-n] [-b] [-h] [-v] [PATH]
3940
4041
Color path components using a palette.
4142
4243
Options:
43-
-p, --palette=PALETTE Semicolon-separated list of styles for
44-
path components
45-
-s, --separator=STYLE Style for path separators
46-
-S, --separator-string=SEPARATOR String used to separate path components
47-
in the output (defaults to '/')
48-
-m, --method=METHOD Method for selecting styles from palette.
49-
One of sequential, hash, random
50-
(defaults to sequential).
51-
-l, --leading Do not display leading path separator
52-
-c, --compact Replace home directory path prefix with ~
53-
-n, --newline Do not append newline
54-
-b, --bash Escape control codes for use in Bash prompts
55-
-h, --help Display this help
56-
-v, --version Display version information
44+
-p, --palette PALETTE Semicolon separated list of styles for
45+
path components
46+
-s, --separator-palette PALETTE Semicolon separated list of styles for
47+
path separators.
48+
-S, --separator SEPARATOR String used to separate path components
49+
in the output (defaults to '/')
50+
-m, --method METHOD Method for selecting styles from palette.
51+
One of sequential, hash, random
52+
(defaults to sequential).
53+
-M, --separator-method METHOD Method for selecting styles from separator
54+
palette. One of sequential, hash, random
55+
(defaults to sequential).
56+
-o, --override INDEX STYLE Override style at the given index. This option
57+
can appear multiple times.
58+
-O, --separator-override INDEX STYLE Override separator style at the given index.
59+
This option can appear multiple times.
60+
-l, --leading Do not display leading path separator
61+
-c, --compact Replace home directory path prefix with ~
62+
-n, --newline Do not append newline
63+
-b, --bash Escape control codes for use in Bash prompts
64+
-h, --help Display this help
65+
-v, --version Display version information
5766
```
5867

5968
### Use in a Bash prompt
@@ -90,13 +99,51 @@ separated by commas. The possible properties are:
9099
| `underlined` | Underlined text |
91100
| `blink` | Blinking text |
92101

93-
Where `COLOR` is an integer between 0 and 255.
102+
Where `COLOR` is an integer between 0 and 255 or one of: `black`, `red`,
103+
`green`, `yellow`, `blue`, `magenta`, `cyan`, `white`.
94104

95-
For example, the following invocation will display the current working
96-
directory's path altering path components' styles between underlined green (2)
97-
and bold yellow (3) on magenta (5) background:
105+
For example, the following invocation will display the path of the current
106+
working directory altering styles of path components between underlined green
107+
text and bold yellow text on magenta background:
98108

99109
``` shell
100-
rainbowpath --palette 'fg=2,underlined;fg=3,bg=5,bold'
110+
rainbowpath --palette 'fg=green,underlined;fg=yellow,bg=magenta,bold'
101111
```
102112

113+
### Style Overrides
114+
115+
`--override` and `--separator-override` options make it possible to selectively
116+
override the style of particular path component at a specific index.
117+
118+
For example, the following command displays all the directory components of the
119+
path as blue, except the first one (index `0` "this") which will be displayed as
120+
yellow.
121+
122+
``` shell
123+
rainbowpath -p 'fg=blue' -o 0 'fg=yellow' '/this/is/an/example/'
124+
```
125+
126+
Component indexes can also be negative, in which case they start at the end of
127+
the list of path components. For example, the following command will print
128+
"example" as yellow.
129+
130+
``` shell
131+
rainbowpath -p 'fg=blue' -o -1 'fg=yellow' '/this/is/an/example/'
132+
```
133+
134+
Override styles are merged with the base style from the palette. For example,
135+
the following command will display example in blue bold font.
136+
137+
``` shell
138+
rainbowpath -p 'fg=blue' -o -1 'bold' '/this/is/an/example/'
139+
```
140+
141+
Override styles are also able to revert style properties set by the base style.
142+
This can be achieved by prefixing the property name with a `!`.
143+
144+
For example, the following command will print all path components in bold yellow
145+
font, except the last one which will be printed in the regular font:
146+
147+
``` shell
148+
rainbowpath -p 'fg=yellow,bold' -o -1 '!fg,!bold' '/this/is/an/example/'
149+
```

man/rainbowpath.1

Lines changed: 72 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'\" t
2-
.TH RAINBOWPATH 1 2018-2019
2+
.TH RAINBOWPATH 1 2018-2020
33

44
.SH NAME
55

@@ -8,26 +8,26 @@ rainbowpath \- Color path components using a palette.
88
.SH SYNOPSIS
99

1010
.B rainbowpath
11-
[\fB\-p\fR \fIPALETTE\fR] [\fB\-s\fR \fISTYLE\fR] [\fB\-S\fR \fISEPARATOR\fR] [\fB\-m\fR \fIMETHOD\fR] [\fB\-l\fR] [\fB\-c\fR] [\fB\-n\fR] [\fB\-b\fR] [\fB\-h\fR] [\fB\-v\fR] [\fIPATH\fR]
11+
[\fB\-p\fR \fIPALETTE\fR] [\fB\-s\fR \fIPALETTE\fR] [\fB\-S\fR \fISEPARATOR\fR] [\fB\-m\fR \fIMETHOD\fR] [\fB\-M\fR \fIMETHOD\fR] [\fB\-o\fR \fIINDEX\fR \fISTYLE\fR] [\fB\-O\fR \fIINDEX\fR \fISTYLE\fR] [\fB\-l\fR] [\fB\-c\fR] [\fB\-n\fR] [\fB\-b\fR] [\fB\-h\fR] [\fB\-v\fR] [\fIPATH\fR]
1212

1313
\fBrainbowpath\fR formats supplied path by coloring each path component with a
1414
color selected from a palette. By default, colors for path components are
1515
selected based on the order they appear in the palette. If no palette is
1616
supplied a default one will be used. When invoked without a path
17-
\fBrainbowpath\fR displays the current working directory.
17+
\fBrainbowpath\fR colors the path of the current working directory.
1818

1919
.SH OPTIONS
2020

2121
.TP
2222
.BI \-p " PALETTE\fR,\fP " \-\-palette " PALETTE"
23-
Semicolon-separated list of styles for path components.
23+
Semicolon separated list of styles for path components.
2424

2525
.TP
26-
.BI \-s " STYLE\fR,\fP " \-\-separator " STYLE"
27-
Style for path separators.
26+
.BI \-s " PALETTE\fR,\fP " \-\-separator\-palette " PALETTE"
27+
Semicolon separated list of styles for path separators.
2828

2929
.TP
30-
.BI \-S " SEPARATOR\fR,\fP " \-\-separator\-string " SEPARATOR"
30+
.BI \-S " SEPARATOR\fR,\fP " \-\-separator " SEPARATOR"
3131
String used to separate path components in the output (defaults to '\fI/\fR').
3232

3333
.TP
@@ -39,6 +39,24 @@ styles based on the order they appear in the palette. \fIhash\fR mode selects
3939
styles based on the contents of path segment being processed. \fIrandom\fR mode
4040
selects styles randomly from the palette.
4141

42+
.TP
43+
.BI \-M " METHOD\fR,\fP " \-\-separator\-method " METHOD"
44+
45+
Method for selecting styles from separator palette. See \fB\-\-method\fR for
46+
further details.
47+
48+
.TP
49+
.BI \-o " INDEX STYLE\fR,\fP " \-\-override " INDEX STYLE"
50+
51+
Override style at the given index. This option can appear multiple times. See
52+
\fBSTYLE OVERRIDES\fR for further details.
53+
54+
.TP
55+
.BI \-O " INDEX STYLE\fR,\fP " \-\-separator\-override " INDEX STYLE"
56+
57+
Override separator style at given the index. This option can appear multiple
58+
times. See \fBSTYLE OVERRIDES\fR for further details.
59+
4260
.TP
4361
.BR \-l ", " \-\-leading
4462
Do not display leading path separator.
@@ -66,8 +84,8 @@ Display version information.
6684
.SH STYLES
6785

6886
Styles specify how path components should look. \fB\-\-palette\fR and
69-
\fB\-\-separator\fR options accept styles as arguments. Style consists of a list
70-
of properties separated by commas. The possible properties are:
87+
\fB\-\-separator\-palette\fR options accept styles as arguments. Style consists
88+
of a list of properties separated by commas. The possible properties are:
7189

7290
.RS
7391
.TS
@@ -83,14 +101,54 @@ blink Blinking text
83101
.TE
84102
.RE
85103

86-
Where \fICOLOR\fR is an integer between \fI0\fR and \fI255\fR.
104+
Where \fICOLOR\fR is an integer between \fI0\fR and \fI255\fR or one of:
105+
\fIblack\fR, \fIred\fR, \fIgreen\fR, \fIyellow\fR, \fIblue\fR, \fImagenta\fR,
106+
\fIcyan\fR, \fIwhite\fR.
107+
108+
For example, the following invocation will display the path of the current
109+
working directory altering styles of path components between underlined green
110+
text and bold yellow text on magenta background:
111+
112+
.nf
113+
rainbowpath --palette 'fg=green,underlined;fg=yellow,bg=magenta,bold'
114+
.fi
115+
116+
.SH STYLE OVERRIDES
117+
118+
\fB\-\-override\fR and \fB\-\-separator-override\fR options make it possible to
119+
selectively override the style of particular path component at a specific index.
120+
121+
For example, the following command displays all the directory components of the
122+
path as blue, except the first one (index \fI0\fR `this') which will be
123+
displayed as yellow.
124+
125+
.nf
126+
rainbowpath -p 'fg=blue' -o 0 'fg=yellow' '/this/is/an/example/'
127+
.fi
128+
129+
Component indexes can also be negative, in which case they start at the end of
130+
the list of path components. For example, the following command will print
131+
`example' as yellow.
132+
133+
.nf
134+
rainbowpath -p 'fg=blue' -o -1 'fg=yellow' '/this/is/an/example/'
135+
.fi
136+
137+
Override styles are merged with the base style from the palette. For example,
138+
the following command will display example in blue bold font.
139+
140+
.nf
141+
rainbowpath -p 'fg=blue' -o -1 'bold' '/this/is/an/example/'
142+
.fi
143+
144+
Override styles are also able to revert style properties set by the base style.
145+
This can be achieved by prefixing the property name with a \fI!\fR.
87146

88-
For example, the following invocation will display the current working
89-
directory's path altering path components' styles between underlined green
90-
(\fI2\fR) and bold yellow (\fI3\fR) on magenta (\fI5\fR) background:
147+
For example, the following command will print all path components in bold yellow
148+
font, except the last one which will be printed in the regular font:
91149

92150
.nf
93-
rainbowpath --palette 'fg=2,underlined;fg=3,bg=5,bold'
151+
rainbowpath -p 'fg=yellow,bold' -o -1 '!fg,!bold' '/this/is/an/example/'
94152
.fi
95153

96154
.SH AUTHORS

0 commit comments

Comments
 (0)