Skip to content

Instantly share code, notes, and snippets.

> echo $PS1
%F{magenta}%n%f at %F{yellow}%m%f in %B%F{green}%~%f%b$(git_prompt_info)$(ruby_prompt_info)
$(virtualenv_info) $(prompt_char)
$(echo -e "\n" | PS1="$WARP_PS1" bash --norc -i 2>&1 | head -2 | tail -1)
sed -E 's/(["\\])/\\\1/g; s/'$'\b''/\\b/g; s/'$'\t''/\\t/g; s/'$'\f''/\\f/g; s/'$'\r''/\\r/g; $!s/$/\\n/'
sed -E 's/'$'\e''/\\e/g; s/'$'\a''/\\a/g; s/(["\\])/\\\1/g; s/'$'\b''/\\b/g; s/'$'\t''/\\t/g; s/'$'\f''/\\f/g; s/'$'\r''/\\r/g; $!s/$/\\n/'
warp_escape_ps1 () {
tr '\n\n' ' ' <<< "$*" | xxd -p | tr -d '\n'
}
# Format a string value according to JSON syntax - Adapted from https://github.com/lework/script.
warp_escape_json () {
# Explanation of the sed replacements (each command is separated by a `;`):
# s/(["\\])/\\\1/g - Replace all double-quote (") and backslash (\) characters with the escaped versions (\" and \\)
# s/\b/\\b/g - Replace all backspace characters with \b
# s/\t/\\t/g - Replace all tab characters with \t