3eda3e5650c72c5f71336fcc2c8dfa5b861acb6d
- Author
- Jeremy Combs <jmcombs@me.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
feat(encode64): add `encodefile64` function (#10813)
Co-authored-by: Jeremy Combs <jeremy.combs@convergetp.com>
Diff
1diff --git a/plugins/encode64/README.md b/plugins/encode64/README.md
2index 86320cffb53445f090cd1514e029ddc5896d6792..7cdf8c3f30d85dbc36c5b88055bbdb9730867b78 100644
3--- a/plugins/encode64/README.md
4+++ b/plugins/encode64/README.md
5@@ -10,10 +10,11 @@ plugins=(... encode64)
6
7 ## Functions and Aliases
8
9-| Function | Alias | Description |
10-| ---------- | ----- | ------------------------------ |
11-| `encode64` | `e64` | Encodes given data to base64 |
12-| `decode64` | `d64` | Decodes given data from base64 |
13+| Function | Alias | Description |
14+| -------------- | ------ | -------------------------------------- |
15+| `encode64` | `e64` | Encodes given data to base64 |
16+| `encodefile64` | `ef64` | Encodes given file's content to base64 |
17+| `decode64` | `d64` | Decodes given data from base64 |
18
19 ## Usage and examples
20
21@@ -37,6 +38,20 @@ plugins=(... encode64)
22 b2gtbXktenNo==
23 ```
24
25+### Encoding a file
26+
27+Encode a file's contents to base64 and save output to text file.
28+**NOTE:** Takes provided file and saves encoded content as new file with `.txt` extension
29+
30+- From parameter
31+
32+ ```console
33+ $ encodefile64 ohmyzsh.icn
34+ ohmyzsh.icn's content encoded in base64 and saved as ohmyzsh.icn.txt
35+ $ ef64 "oh-my-zsh"
36+ ohmyzsh.icn's content encoded in base64 and saved as ohmyzsh.icn.txt
37+ ```
38+
39 ### Decoding
40
41 - From parameter
42diff --git a/plugins/encode64/encode64.plugin.zsh b/plugins/encode64/encode64.plugin.zsh
43index 979e067429873d610d0f0878c28fbf0eec48d9cf..6927f5216120babe02dfd91f287659d2e8ea1099 100644
44--- a/plugins/encode64/encode64.plugin.zsh
45+++ b/plugins/encode64/encode64.plugin.zsh
46@@ -6,6 +6,15 @@ encode64() {
47 fi
48 }
49
50+encodefile64() {
51+ if [[ $# -eq 0 ]]; then
52+ echo "You must provide a filename"
53+ else
54+ base64 -i $1 -o $1.txt
55+ echo "${1}'s content encoded in base64 and saved as ${1}.txt"
56+ fi
57+}
58+
59 decode64() {
60 if [[ $# -eq 0 ]]; then
61 cat | base64 --decode
62@@ -14,4 +23,5 @@ decode64() {
63 fi
64 }
65 alias e64=encode64
66+alias ef64=encodefile64
67 alias d64=decode64