Skip to content

Instantly share code, notes, and snippets.

@pwsandoval
Last active March 14, 2023 00:35
Show Gist options
  • Save pwsandoval/79499fbfde43e0a72410d711a5a92a25 to your computer and use it in GitHub Desktop.
Save pwsandoval/79499fbfde43e0a72410d711a5a92a25 to your computer and use it in GitHub Desktop.
__vte_urlencode() (
# This is important to make sure string manipulation is handled
# byte-by-byte.
LC_ALL=C
str="$1"
while [ -n "$str" ]; do
safe="${str%%[!a-zA-Z0-9/:_\.\-\!\'\(\)~]*}"
printf "%s" "$safe"
str="${str#"$safe"}"
if [ -n "$str" ]; then
printf "%%%02X" "'$str"
str="${str#?}"
fi
done
)
__vte_osc7 () {
printf "\033]7;file://%s%s\007" "${HOSTNAME:-}" "$(__vte_urlencode "${PWD}")"
}
# This is only necessary for bash
#__vte_prompt_command() {
# local command=$(HISTTIMEFORMAT= history 1 | sed 's/^ *[0-9]\+ *//')
# command="${command//;/ }"
# local pwd='~'
# [ "$PWD" != "$HOME" ] && pwd=${PWD/#$HOME\//\~\/}
# printf "\033]777;notify;Command completed;%s\007\033]0;%s@%s:%s\007%s" "${command}" "${USER}" "${HOSTNAME%%.*}" "${pwd}" "$(__vte_osc7)"
#}
case "$TERM" in
xterm*|vte*)
[ -n "$BASH_VERSION" ] && PROMPT_COMMAND="__vte_prompt_command"
[ -n "$ZSH_VERSION" ] && precmd_functions+=(__vte_osc7)
;;
esac
true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment