Prompt fixes in zsh.
This commit is contained in:
parent
cfc5cdbb6f
commit
d8d47433d0
@ -14,7 +14,7 @@ function symlink_dotfiles() {
|
||||
mkdir ~/.dotfiles-backups
|
||||
for filename in *; do
|
||||
local link_destination="$HOME/.$filename"
|
||||
local absolute_path="$($readlink_command -f $filename)"
|
||||
local absolute_path="$(readlink -f $filename)"
|
||||
echo "linking $link_destination to $absolute_path"
|
||||
[[ -a $link_destination ]] && mv $link_destination ~/.dotfiles-backups
|
||||
ln -si $absolute_path $link_destination
|
||||
|
@ -1,39 +1 @@
|
||||
# Add `~/bin` to the `$PATH`
|
||||
export PATH="$HOME/bin:$PATH"
|
||||
|
||||
# Load the shell dotfiles, and then some:
|
||||
# * ~/.path can be used to extend `$PATH`.
|
||||
# * ~/.extra can be used for other settings you don’t want to commit.
|
||||
for file in ~/.{path,bash_prompt,exports,shared_exports,aliases,functions,extra}; do
|
||||
[ -r "$file" ] && source "$file"
|
||||
done
|
||||
unset file
|
||||
|
||||
# Case-insensitive globbing (used in pathname expansion)
|
||||
shopt -s nocaseglob
|
||||
|
||||
# Append to the Bash history file, rather than overwriting it
|
||||
shopt -s histappend
|
||||
|
||||
# Autocorrect typos in path names when using `cd`
|
||||
shopt -s cdspell
|
||||
|
||||
# Enable some Bash 4 features when possible:
|
||||
# * `autocd`, e.g. `**/qux` will enter `./foo/bar/baz/qux`
|
||||
# * Recursive globbing, e.g. `echo **/*.txt`
|
||||
for option in autocd globstar; do
|
||||
shopt -s "$option" 2> /dev/null
|
||||
done
|
||||
|
||||
# Add tab completion for SSH hostnames based on ~/.ssh/config, ignoring wildcards
|
||||
[ -e "$HOME/.ssh/config" ] && complete -o "default" -o "nospace" -W "$(grep "^Host" ~/.ssh/config | grep -v "[?*]" | cut -d " " -f2)" scp sftp ssh
|
||||
|
||||
# Add tab completion for `defaults read|write NSGlobalDomain`
|
||||
# You could just use `-g` instead, but I like being explicit
|
||||
complete -W "NSGlobalDomain" defaults
|
||||
|
||||
# Add `killall` tab completion for common apps
|
||||
complete -o "nospace" -W "Contacts Calendar Dock Finder Mail Safari iTunes SystemUIServer Terminal Twitter" killall
|
||||
|
||||
# If possible, add tab completion for many more commands
|
||||
[ -f /etc/bash_completion ] && source /etc/bash_completion
|
||||
source ~/.bashrc
|
@ -0,0 +1,3 @@
|
||||
for filename in ~/.lib/bash/*; do
|
||||
source $filename
|
||||
done
|
15
dotfiles/lib/bash/prompt.sh
Normal file
15
dotfiles/lib/bash/prompt.sh
Normal file
@ -0,0 +1,15 @@
|
||||
function current_directory() {
|
||||
local PWD=$(pwd)
|
||||
echo "${PWD/#$HOME/~}"
|
||||
}
|
||||
|
||||
function git_prompt_info () {
|
||||
if test -z $(parse_git_branch);
|
||||
then
|
||||
echo ""
|
||||
else
|
||||
echo "on $(parse_git_branch)"
|
||||
fi
|
||||
}
|
||||
|
||||
PS1='%u at $(hostname -s) in $(current_directory) $(git_prompt_info) $(colored_sandbox_string) '
|
@ -35,6 +35,8 @@ command -v md5sum > /dev/null || alias md5sum="md5"
|
||||
# OS X has no `sha1sum`, so use `shasum` as a fallback
|
||||
command -v sha1sum > /dev/null || alias sha1sum="shasum"
|
||||
|
||||
command -v greadlink > /dev/null && alias readlink="greadlink"
|
||||
|
||||
# URL-encode strings
|
||||
alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"'
|
||||
|
||||
|
@ -4,8 +4,12 @@ function parse_git_branch() {
|
||||
echo ${ref#refs/heads/}
|
||||
}
|
||||
|
||||
function git_is_dirty() {
|
||||
git diff-index --quiet --cached HEAD && git diff-files --quiet
|
||||
}
|
||||
|
||||
function current_shell() {
|
||||
ps -p $$ | tail -1 | awk '{print $NF}' | xargs which | xargs readlink -f
|
||||
greadlink -f $(which "$(ps -p $$ | tail -1 | awk '{print $NF}' | sed 's/\-//')")
|
||||
}
|
||||
|
||||
function is_zsh() {
|
||||
|
@ -51,7 +51,8 @@ function sandbox_prompt_info() {
|
||||
if [ "$YELP_IN_SANDBOX" ];
|
||||
then
|
||||
sandbox_string=$sandbox_string"sandbox-$(get_sandbox_identifier)"
|
||||
else
|
||||
elif [ ! -z $(env | grep YELP) ];
|
||||
then
|
||||
sandbox_string="no sandbox"
|
||||
fi
|
||||
echo $sandbox_string
|
||||
@ -77,11 +78,11 @@ function zsh_sandbox_color() {
|
||||
}
|
||||
|
||||
function colored_sandbox_string() {
|
||||
if [ is_zsh ]
|
||||
if [ is_zsh ];
|
||||
then
|
||||
sandbox_color=$(zsh_sandbox_color)
|
||||
else
|
||||
sandbox_color=$(bash_sandbox_color)
|
||||
fi
|
||||
echo $sandbox_color$(sandbox_prompt_info)
|
||||
echo "$sandbox_color$(sandbox_prompt_info)%{$reset_color%}"
|
||||
}
|
||||
|
@ -8,11 +8,28 @@ function git_prompt_info () {
|
||||
then
|
||||
echo ""
|
||||
else
|
||||
echo " %{$FG[239]%}on%{$reset_color%} %{$FG[255]%}$(parse_git_branch)%{$reset_color%}"
|
||||
echo " %{$FG[239]%}on%{$reset_color%} %{$FG[255]%}$(parse_git_branch)%{$reset_color%}$(git_status_character)"
|
||||
fi
|
||||
}
|
||||
|
||||
PROMPT='%{$FG[040]%}%n%{$reset_color%} %{$FG[239]%}at%{$reset_color%} %{$FG[033]%}$(hostname -s)%{$reset_color%} %{$FG[239]%}in%{$reset_color%} %{$terminfo[bold]$FG[226]%}$(current_directory)%{$reset_color%}$(git_prompt_info) %{$FG[239]%}with $(colored_sandbox_string)%{$FG[255]%}%{$reset_color%} '
|
||||
function git_status_character() {
|
||||
if git_is_dirty;
|
||||
then
|
||||
echo "%{$FG[202]%}✘%{$reset_color%}"
|
||||
else
|
||||
echo "%{$FG[040]%}✔%{$reset_color%}"
|
||||
fi
|
||||
}
|
||||
|
||||
function sandbox_prompt() {
|
||||
if [ ! -z $(sandbox_prompt_info) ];
|
||||
then
|
||||
echo " %{$FG[239]%}with $(colored_sandbox_string)%{$reset_color%}"
|
||||
fi
|
||||
}
|
||||
|
||||
PROMPT='╭─% %{$FG[040]%}%n%{$reset_color%} %{$FG[239]%}at%{$reset_color%} %{$FG[033]%}$(hostname -s)%{$reset_color%} %{$FG[239]%}in%{$reset_color%} %{$terminfo[bold]$FG[226]%}$(current_directory)%{$reset_color%}$(git_prompt_info)$(sandbox_prompt)
|
||||
$FG[255]╰─± '
|
||||
|
||||
PS2=''
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user