mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-11-25 07:04:22 +03:00
* 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>
41 lines
879 B
Bash
41 lines
879 B
Bash
encode64() {
|
|
if [[ $# -eq 0 ]]; then
|
|
cat | base64
|
|
else
|
|
printf '%s' "$1" | base64
|
|
fi
|
|
}
|
|
|
|
encodefile64() {
|
|
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 -d
|
|
else
|
|
printf '%s' "$1" | base64 -d
|
|
fi
|
|
}
|
|
alias e64=encode64
|
|
alias ef64=encodefile64
|
|
alias d64=decode64
|