Skip to content

Instantly share code, notes, and snippets.

@acook
Created September 6, 2011 21:06
Show Gist options
  • Save acook/1198970 to your computer and use it in GitHub Desktop.
Save acook/1198970 to your computer and use it in GitHub Desktop.
Provides helpers for making prompts.
#!/bin/bash
# Just some stuff to make writing prompts easier
# Set a Terminal's title with this, saves a lot of weird strings from the prompts
function title { echo -ne "\\033]0;$*\007"; }
# Gets the present working directory and returns just the last 2 directories, good for shortening titles and prompts
function PWD { tmp=${PWD%/*/*}; [ ${#tmp} -gt 0 -a "$tmp" != "$PWD" ] && echo ${PWD:${#tmp}+1} || echo $PWD; }
# Does the same thing, but for any path
function shortpath { tmp=${1%/*/*}; [ ${#tmp} -gt 0 -a "$tmp" != "$1" ] && echo ${1:${#tmp}+1} || echo $1; }
# Here's a bunch of my old prompt strings, I should probably check these out and toss the crappy ones
#PS1="\$?-\t | \$(PWD)\n\r\$ "
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
#PS1='${debian_chroot:+($debian_chroot)}\033[00;31m\u@\h:\033[01;33m\w\033[00m\n\r\[\033[01;31m\$\033[00m\] '
#PS1='\033]0;$(PWD)\007\033[00;31m\u@\h:\033[01;33m\w\033[00m\n\r\[\033[01;31m\$\033[00m\] '
#PS1='\[$(title $(PWD))$(fgx 154)\]\w\n\[\r\]\[$(fgx 26)\]\$\[$(fg_reset)\] '
# Here's the old, outdated way of setting Terminal titles
#function prompt_command { echo -ne "\033]0;$(PWD)\007" }
#PROMPT_COMMAND="prompt_command"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment