# Allows for colored output after pipe
# https://wiki.archlinux.org/index.php/Color_output_in_console
zmodload zsh/zpty

pty() {
        zpty pty-${UID} ${1+$@}
        if [[ ! -t 1 ]];then
                setopt local_traps
                trap '' INT
        fi
        zpty -r pty-${UID}
        zpty -d pty-${UID}
}

# Allows for colored output after pipe, and tee's the output somewhere.
# Usage: pty <command> <output file>

ptytee() {
        pty $1 | tee -a $2
}

# Does powershell (unicode) b64 encoding of string
# Usage: ps-encode [string]
ps-encode() {
	text="$1" pwsh -command '$bytes = [System.Text.Encoding]::Unicode.GetBytes($env:text); $enc = [Convert]::ToBase64String($bytes); $enc'
}

# Does powershell (unicode) b64 decode of string
# Usage: ps-decode [encoded string]
ps-decode() {
	text="$1" pwsh -command '$enc = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($env:text)); $enc'
}
