mirror of
https://github.com/robbyrussell/oh-my-zsh.git
synced 2026-11-25 01:43:04 +01:00
fix(encode64): support BSD base64 and quote arguments (#14269)
* encode64: support BSD base64 and quote arguments * chore: remove pr-body.md and pr-title.txt from branch --------- Co-authored-by: pei711 <pei711@users.noreply.github.com> Co-authored-by: pei711 <3922088406@qq.com>
This commit is contained in:
3 files changed
+101
-11
No files matched your search
@@ -2,24 +2,37 @@ encode64() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
cat | base64
|
||||
else
|
||||
printf '%s' $1 | base64
|
||||
printf '%s' "$1" | base64
|
||||
fi
|
||||
}
|
||||
|
||||
encodefile64() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
echo "You must provide a filename"
|
||||
else
|
||||
base64 $1 > $1.txt
|
||||
echo "${1}'s content encoded in base64 and saved as ${1}.txt"
|
||||
if [[ $# -ne 1 || ! -f "$1" || ! -r "$1" ]]; then
|
||||
print -u2 -- 'Usage: encodefile64 <file>'
|
||||
return 1
|
||||
fi
|
||||
|
||||
local file="$1" output="${1}.txt" tmp_file
|
||||
[[ $output == /* ]] || output="./$output"
|
||||
|
||||
tmp_file=$(mktemp "${output}.XXXXXX") || return 1
|
||||
if ! base64 < "$file" > "$tmp_file"; then
|
||||
command rm -f "$tmp_file"
|
||||
return 1
|
||||
fi
|
||||
if ! command mv "$tmp_file" "$output"; then
|
||||
command rm -f "$tmp_file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
print -- "$file's content encoded in base64 and saved as ${file}.txt"
|
||||
}
|
||||
|
||||
decode64() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
cat | base64 --decode
|
||||
cat | base64 -d
|
||||
else
|
||||
printf '%s' $1 | base64 --decode
|
||||
printf '%s' "$1" | base64 -d
|
||||
fi
|
||||
}
|
||||
alias e64=encode64
|
||||
|
||||
Reference in new issue
Block a user