Skip to content

Commit f40de40

Browse files
committed
Improve shell syntax highlighting
As is, there are several code blocks with lines prefixed with `$`, indicating to me that they want to mimic a shell session. These code blocks are marked with either `sh` or `bash` tags, to suggest syntax highlighting appropriate for such shell sessions. This doesn't seem ideal, because command output is highlighted just as if it was another shell command. Hugo uses the Chroma syntax highlighter, which provides a dedicated lexer specifically for such scenarios. This change makes use of that lexer to improve the formatting. There were several cases where lines in these code blocks wanted to indicate comments using `#`, which indicates a comment in a shell script. However, because `#` commonly indicates the prompt of a root shell, such lines had to be adjusted to correctly reflect shell usage, where the comment would be entered on the prompt. The type `console` was specifically chosen in favor over other tags (like `bash-session`), because the docsy theme specifically supports this language tag to improve the user experience on such code blocks. The copy-to-clipboard behavior will not copy command output, or the prompt character, in these cases. Signed-off-by: Oliver Salzburg <oliver.salzburg@adesso.de>
1 parent 704df0b commit f40de40

17 files changed

Lines changed: 117 additions & 119 deletions

File tree

content/en/docs/installation/_index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Binaries and packages of the latest stable release are available at
1414
For the adventurous, unstable features are available in the
1515
[main](https://github.com/getsops/sops/commits/main/) branch, which you can install from source:
1616

17-
``` bash
17+
``` console
1818
$ mkdir -p $GOPATH/src/github.com/getsops/sops/
1919
$ git clone https://github.com/getsops/sops.git $GOPATH/src/github.com/getsops/sops/
2020
$ cd $GOPATH/src/github.com/getsops/sops/
@@ -25,7 +25,7 @@ $ make install
2525

2626
If you don\'t have Go installed, set it up with:
2727

28-
``` bash
28+
``` console
2929
$ {apt,yum,brew} install golang
3030
$ echo 'export GOPATH=~/go' >> ~/.bashrc
3131
$ source ~/.bashrc

content/en/docs/reference/_index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ be decrypted in the same format. The easiest way to achieve this is to
1919
conserve the original file extension after encrypting a file. For
2020
example:
2121

22-
``` sh
22+
``` console
2323
$ sops encrypt -i myfile.json
2424
$ sops decrypt myfile.json
2525
```
@@ -28,7 +28,7 @@ If you want to change the extension of the file once encrypted, you need
2828
to provide `sops` with the `--input-type` flag upon decryption. For
2929
example:
3030

31-
``` sh
31+
``` console
3232
$ sops encrypt myfile.json > myfile.json.enc
3333

3434
$ sops decrypt --input-type json myfile.json.enc
@@ -37,7 +37,7 @@ $ sops decrypt --input-type json myfile.json.enc
3737
When operating on stdin, use the `--input-type` and `--output-type`
3838
flags as follows:
3939

40-
``` sh
40+
``` console
4141
$ cat myfile.json | sops decrypt --input-type json --output-type json
4242
```
4343

content/en/docs/security/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ encrypted PGP file: by referencing the pubkeys of each individual who
112112
has access to the file. It can easily be done by providing SOPS with a
113113
comma-separated list of public keys when creating a new file:
114114

115-
``` sh
115+
``` console
116116
$ sops edit --pgp "E60892BB9BD89A69F759A1A0A3D652173B763E8F,84050F1D61AF7C230A12217687DF65059EF093D3,85D77543B3D624B63CEA9E6DBC17301B491B3F21" mynewfile.yaml
117117
```
118118

content/en/docs/usage/advanced/_index.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ select the correct creation rule.
1818

1919
The simplest way to decrypt data from stdin is as follows:
2020

21-
``` sh
21+
``` console
2222
$ cat encrypted-data | sops decrypt > decrypted-data
2323
```
2424

@@ -31,7 +31,7 @@ To avoid this, you can either provide a filename with `--filename-override`,
3131
or explicitly control the input and output formats by passing
3232
`--input-type` and `--output-type` as appropriate:
3333

34-
``` sh
34+
``` console
3535
$ cat encrypted-data | sops decrypt --filename-override filename.yaml > decrypted-data
3636
$ cat encrypted-data | sops decrypt --input-type yaml --output-type yaml > decrypted-data
3737
```
@@ -45,7 +45,7 @@ look up the correct creation rule from `.sops.yaml`. Therefore, you must
4545
provide the `--filename-override` parameter which allows you to tell
4646
SOPS which filename to use to match creation rules:
4747

48-
``` sh
48+
``` console
4949
$ echo 'foo: bar' | sops encrypt --filename-override path/filename.sops.yaml > encrypted-data
5050
```
5151

@@ -55,7 +55,7 @@ filename will also be used to determine the input and output store. As
5555
always, the input store type can be adjusted by passing `--input-type`,
5656
and the output store type by passing `--output-type`:
5757

58-
``` sh
58+
``` console
5959
$ echo foo=bar | sops encrypt --filename-override path/filename.sops.yaml --input-type dotenv > encrypted-data
6060
```
6161

@@ -115,27 +115,27 @@ respectively. For example, if a program looks for credentials in its
115115
environment, `exec-env` can be used to ensure that the decrypted
116116
contents are available only to this process and never written to disk.
117117

118-
``` sh
119-
# print secrets to stdout to confirm values
118+
``` console
119+
$ # print secrets to stdout to confirm values
120120
$ sops decrypt out.json
121121
{
122122
"database_password": "jf48t9wfw094gf4nhdf023r",
123123
"AWS_ACCESS_KEY_ID": "AKIAIOSFODNN7EXAMPLE",
124124
"AWS_SECRET_KEY": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
125125
}
126126
127-
# decrypt out.json and run a command
128-
# the command prints the environment variable and runs a script that uses it
127+
$ # decrypt out.json and run a command
128+
$ # the command prints the environment variable and runs a script that uses it
129129
$ sops exec-env out.json 'echo secret: $database_password; ./database-import'
130130
secret: jf48t9wfw094gf4nhdf023r
131131
132-
# launch a shell with the secrets available in its environment
132+
$ # launch a shell with the secrets available in its environment
133133
$ sops exec-env out.json 'sh'
134-
sh-3.2# echo $database_password
134+
$ echo $database_password
135135
jf48t9wfw094gf4nhdf023r
136136
137-
# the secret is not accessible anywhere else
138-
sh-3.2$ exit
137+
$ # the secret is not accessible anywhere else
138+
$ exit
139139
$ echo your password: $database_password
140140
your password:
141141
```
@@ -154,31 +154,31 @@ the process is finished executing. `exec-file` behaves similar to
154154
will be substituted with the temporary file path (whether a FIFO or an
155155
actual file).
156156

157-
``` sh
158-
# operating on the same file as before, but as a file this time
159-
$ sops exec-file out.json 'echo your temporary file: {}; cat {}'
157+
``` console
158+
% # operating on the same file as before, but as a file this time
159+
% sops exec-file out.json 'echo your temporary file: {}; cat {}'
160160
your temporary file: /tmp/.sops894650499/tmp-file
161161
{
162162
"database_password": "jf48t9wfw094gf4nhdf023r",
163163
"AWS_ACCESS_KEY_ID": "AKIAIOSFODNN7EXAMPLE",
164164
"AWS_SECRET_KEY": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
165165
}
166166
167-
# launch a shell with a variable TMPFILE pointing to the temporary file
168-
$ sops exec-file --no-fifo out.json 'TMPFILE={} sh'
169-
sh-3.2$ echo $TMPFILE
167+
% # launch a shell with a variable TMPFILE pointing to the temporary file
168+
% sops exec-file --no-fifo out.json 'TMPFILE={} sh'
169+
$ echo $TMPFILE
170170
/tmp/.sops506055069/tmp-file291138648
171-
sh-3.2$ cat $TMPFILE
171+
$ cat $TMPFILE
172172
{
173173
"database_password": "jf48t9wfw094gf4nhdf023r",
174174
"AWS_ACCESS_KEY_ID": "AKIAIOSFODNN7EXAMPLE",
175175
"AWS_SECRET_KEY": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
176176
}
177-
sh-3.2$ ./program --config $TMPFILE
178-
sh-3.2$ exit
177+
$ ./program --config $TMPFILE
178+
$ exit
179179
180-
# try to open the temporary file from earlier
181-
$ cat /tmp/.sops506055069/tmp-file291138648
180+
% # try to open the temporary file from earlier
181+
% cat /tmp/.sops506055069/tmp-file291138648
182182
cat: /tmp/.sops506055069/tmp-file291138648: No such file or directory
183183
```
184184

@@ -192,20 +192,20 @@ possible for added security.
192192
To overwrite the default file name (`tmp-file`) in `exec-file` use the
193193
`--filename <filename>` parameter.
194194

195-
``` sh
196-
# the encrypted file can't be read by the current user
197-
$ cat out.json
195+
``` console
196+
% # the encrypted file can't be read by the current user
197+
% cat out.json
198198
cat: out.json: Permission denied
199199
200-
# execute sops as root, decrypt secrets, then drop privileges
201-
$ sudo sops exec-env --user nobody out.json 'sh'
202-
sh-3.2$ echo $database_password
200+
% # execute sops as root, decrypt secrets, then drop privileges
201+
% sudo sops exec-env --user nobody out.json 'sh'
202+
$ echo $database_password
203203
jf48t9wfw094gf4nhdf023r
204204
205-
# dropped privileges, still can't load the original file
206-
sh-3.2$ id
205+
$ # dropped privileges, still can't load the original file
206+
$ id
207207
uid=4294967294(nobody) gid=4294967294(nobody) groups=4294967294(nobody)
208-
sh-3.2$ cat out.json
208+
$ cat out.json
209209
cat: out.json: Permission denied
210210
```
211211

@@ -248,13 +248,13 @@ For example, to decrypt a file using both the local key service and the
248248
key service exposed on the unix socket located in `/tmp/sops.sock`, you
249249
can run:
250250

251-
``` sh
251+
``` console
252252
$ sops decrypt --keyservice unix:///tmp/sops.sock file.yaml
253253
```
254254

255255
And if you only want to use the key service exposed on the unix socket
256256
located in `/tmp/sops.sock` and not the local key service, you can run:
257257

258-
``` sh
258+
``` console
259259
$ sops decrypt --enable-local-keyservice=false --keyservice unix:///tmp/sops.sock file.yaml
260260
```

content/en/docs/usage/common-operations/_index.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ result in an error.
2323
The command below creates a new file with a data key encrypted by KMS
2424
and PGP.
2525

26-
``` sh
26+
``` console
2727
$ sops edit --kms "arn:aws:kms:us-west-2:927034868273:key/fe86dd69-4132-404c-ab86-4269956b4500" --pgp C9CAB0AF1165060DB58D6D6B2653B624D620786D /path/to/new/file.yaml
2828
```
2929

@@ -34,15 +34,15 @@ key. The path points to an existing cleartext file, so we give `sops`
3434
the flag `-e` to encrypt the file, and redirect the output to a
3535
destination file.
3636

37-
``` sh
37+
``` console
3838
$ export SOPS_KMS_ARN="arn:aws:kms:us-west-2:927034868273:key/fe86dd69-4132-404c-ab86-4269956b4500"
3939
$ export SOPS_PGP_FP="C9CAB0AF1165060DB58D6D6B2653B624D620786D"
4040
$ sops encrypt /path/to/existing/file.yaml > /path/to/new/encrypted/file.yaml
4141
```
4242

4343
Decrypt the file with `-d`.
4444

45-
``` sh
45+
``` console
4646
$ sops decrypt /path/to/new/encrypted/file.yaml
4747
```
4848

@@ -51,12 +51,12 @@ $ sops decrypt /path/to/new/encrypted/file.yaml
5151
Rather than redirecting the output of `-e` or `-d`, `sops` can replace
5252
the original file after encrypting or decrypting it.
5353

54-
``` sh
55-
# file.yaml is in cleartext
54+
``` console
55+
$ # file.yaml is in cleartext
5656
$ sops encrypt -i /path/to/existing/file.yaml
57-
# file.yaml is now encrypted
57+
$ # file.yaml is now encrypted
5858
$ sops decrypt -i /path/to/existing/file.yaml
59-
# file.yaml is back in cleartext
59+
$ # file.yaml is back in cleartext
6060
```
6161

6262
## Encrypting binary files
@@ -71,7 +71,7 @@ encrypted file larger than the cleartext one.
7171

7272
In-place encryption/decryption also works on binary files.
7373

74-
``` sh
74+
``` console
7575
$ dd if=/dev/urandom of=/tmp/somerandom bs=1024
7676
count=512
7777
512+0 records in
@@ -96,7 +96,7 @@ SOPS can extract a specific part of a YAML or JSON document, by provided
9696
the path in the `--extract` command line flag. This is useful to extract
9797
specific values, like keys, without needing an extra parser.
9898

99-
``` sh
99+
``` console
100100
$ sops decrypt --extract '["app2"]["key"]' ~/git/svc/sops/example.yaml
101101
-----BEGIN RSA PRIVATE KEY-----
102102
MIIBPAIBAAJBAPTMNIyHuZtpLYc7VsHQtwOkWYobkUblmHWRmbXzlAX6K8tMf3Wf
@@ -113,7 +113,7 @@ The tree path syntax uses regular python dictionary syntax, without the
113113
variable name. Extract keys by naming them, and array elements by
114114
numbering them.
115115

116-
``` sh
116+
``` console
117117
$ sops decrypt --extract '["an_array"][1]' ~/git/svc/sops/example.yaml
118118
secretuser2
119119
```
@@ -124,32 +124,32 @@ SOPS can set a specific part of a YAML or JSON document, by providing
124124
the path and value in the `set` command. This is useful to set specific
125125
values, like keys, without needing an editor.
126126

127-
``` sh
127+
``` console
128128
$ sops set ~/git/svc/sops/example.yaml '["app2"]["key"]' '"app2keystringvalue"'
129129
```
130130

131131
The tree path syntax uses regular python dictionary syntax, without the
132132
variable name. Set to keys by naming them, and array elements by
133133
numbering them.
134134

135-
``` sh
135+
``` console
136136
$ sops set ~/git/svc/sops/example.yaml '["an_array"][1]' '"secretuser2"'
137137
```
138138

139139
The value must be formatted as json.
140140

141-
``` sh
141+
``` console
142142
$ sops set ~/git/svc/sops/example.yaml '["an_array"][1]' '{"uid1":null,"uid2":1000,"uid3":["bob"]}'
143143
```
144144

145145
You can also provide the value from a file or stdin:
146146

147-
``` sh
148-
# Provide the value from a file
147+
``` console
148+
$ # Provide the value from a file
149149
$ echo '{"uid1":null,"uid2":1000,"uid3":["bob"]}' > /tmp/example-value
150150
$ sops set --value-file ~/git/svc/sops/example.yaml '["an_array"][1]' /tmp/example-value
151151

152-
# Provide the value from stdin
152+
$ # Provide the value from stdin
153153
$ echo '{"uid1":null,"uid2":1000,"uid3":["bob"]}' | sops set --value-stdin ~/git/svc/sops/example.yaml '["an_array"][1]'
154154
```
155155

@@ -159,15 +159,15 @@ Symmetrically, SOPS can unset a specific part of a YAML or JSON document, by pro
159159
the path in the `unset` command. This is useful to unset specific values, like keys, without
160160
needing an editor.
161161

162-
``` sh
162+
``` console
163163
$ sops unset ~/git/svc/sops/example.yaml '["app2"]["key"]'
164164
```
165165

166166
The tree path syntax uses regular python dictionary syntax, without the
167167
variable name. Set to keys by naming them, and array elements by
168168
numbering them.
169169

170-
``` sh
170+
``` console
171171
$ sops unset ~/git/svc/sops/example.yaml '["an_array"][1]'
172172
```
173173

@@ -190,7 +190,7 @@ Here we only care about YAML files. `sopsdiffer` is an arbitrary name
190190
that we map to a SOPS command in the git configuration file of the
191191
repository.
192192

193-
``` sh
193+
``` console
194194
$ git config diff.sopsdiffer.textconv "sops decrypt"
195195

196196
$ grep -A 1 sopsdiffer .git/config
@@ -234,7 +234,7 @@ A third method is to use the `--encrypted-regex` which will only encrypt
234234
values under keys that match the supplied regular expression. For
235235
example, this command:
236236

237-
``` sh
237+
``` console
238238
$ sops encrypt --encrypted-regex '^(data|stringData)$' k8s-secrets.yaml
239239
```
240240

@@ -248,7 +248,7 @@ by using the `--unencrypted-regex` option, which will leave the values
248248
unencrypted of those keys that match the supplied regular expression.
249249
For example, this command:
250250

251-
``` sh
251+
``` console
252252
$ sops encrypt --unencrypted-regex '^(description|metadata)$' k8s-secrets.yaml
253253
```
254254

0 commit comments

Comments
 (0)