Compare commits
4 commits
04962b7d54
...
76e437cb4e
Author | SHA1 | Date | |
---|---|---|---|
76e437cb4e | |||
3bc9a5c66d | |||
42be2b7935 | |||
96a3d6d261 |
4 changed files with 64 additions and 23 deletions
6
.bashrc
6
.bashrc
|
@ -69,3 +69,9 @@ add_path() {
|
||||||
for dot in ~/bin/dotlib/*.sh; do
|
for dot in ~/bin/dotlib/*.sh; do
|
||||||
. "$dot"
|
. "$dot"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
###
|
||||||
|
# Reset exit status
|
||||||
|
###
|
||||||
|
|
||||||
|
true
|
||||||
|
|
|
@ -3,10 +3,10 @@ reset-elapsed() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ping-timer() {
|
ping-timer() {
|
||||||
kill -USR1 "$reaper_pid" 2>/dev/null
|
kill -USR1 "$reaper_pid"
|
||||||
}
|
}
|
||||||
|
|
||||||
kill-reaper() {
|
slay-reaper() {
|
||||||
kill -KILL "$reaper_pid"
|
kill -KILL "$reaper_pid"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,4 +25,4 @@ kill-reaper() {
|
||||||
} &
|
} &
|
||||||
|
|
||||||
reaper_pid=$! PROMPT_COMMAND+=(ping-timer)
|
reaper_pid=$! PROMPT_COMMAND+=(ping-timer)
|
||||||
trap kill-reaper EXIT
|
trap slay-reaper EXIT
|
||||||
|
|
25
dotlib/iterm2.sh
Normal file
25
dotlib/iterm2.sh
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# Based on the iTerm2 Bash integration script
|
||||||
|
|
||||||
|
if [[ $OSTYPE != darwin* ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
iterm2_write() {
|
||||||
|
local cmd=$1 fmt=$2
|
||||||
|
shift 2
|
||||||
|
printf "\033]1337;%s=$fmt\007" "$cmd" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
iterm2_write_state() {
|
||||||
|
iterm2_write RemoteHost %s@%s "$USER" "$iterm2_hostname"
|
||||||
|
iterm2_write CurrentDir %s "$PWD"
|
||||||
|
}
|
||||||
|
|
||||||
|
iterm2_prompt_command() {
|
||||||
|
iterm2_write_state
|
||||||
|
}
|
||||||
|
|
||||||
|
ITERM_SHELL_INTEGRATION_INSTALLED=Yes
|
||||||
|
ITERM_PREV_PS1=$PS1
|
||||||
|
iterm2_hostname=${HOSTNAME-"$(hostname -f 2>/dev/null)"}
|
||||||
|
PROMPT_COMMAND+=(iterm2_prompt_command)
|
|
@ -1,3 +1,30 @@
|
||||||
|
setup-prompt() {
|
||||||
|
local last_res=$? color=$PS1_color_green
|
||||||
|
PS1="\w "
|
||||||
|
|
||||||
|
if [[ -d .git ]]; then
|
||||||
|
PS1+="$(command git branch --show-current) "
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -v SSH_CLIENT ]]; then
|
||||||
|
PS1+="$PS1_hostname "
|
||||||
|
fi
|
||||||
|
|
||||||
|
if (( last_res )); then
|
||||||
|
color=$PS1_color_red
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
PS1+="\[$color\][$last_res]\[$PS1_color_reset\] $PS1_prompt_sym "
|
||||||
|
}
|
||||||
|
|
||||||
|
PS1_prompt_sym=λ
|
||||||
|
PS1_hostname=${HOSTNAME-"$(hostname)"}
|
||||||
|
PS1_color_red=$(tput setaf 1)
|
||||||
|
PS1_color_green=$(tput setaf 2)
|
||||||
|
PS1_color_reset=$(tput sgr0)
|
||||||
|
PROMPT_COMMAND+=(setup-prompt)
|
||||||
|
|
||||||
read -r month day < <(date "+%m %d")
|
read -r month day < <(date "+%m %d")
|
||||||
|
|
||||||
if (( 10#$month == 3 && 10#$day < 18 )); then
|
if (( 10#$month == 3 && 10#$day < 18 )); then
|
||||||
|
@ -7,7 +34,7 @@ if (( 10#$month == 3 && 10#$day < 18 )); then
|
||||||
printf "Only %d days left until Saint Patrick's day!\n" "$(( 17 - 10#$day ))"
|
printf "Only %d days left until Saint Patrick's day!\n" "$(( 17 - 10#$day ))"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
prompt_sym=🍀
|
PS1_prompt_sym=🍀
|
||||||
elif (( 10#$month == 10 )); then
|
elif (( 10#$month == 10 )); then
|
||||||
if (( 31 - 10#$day == 0 )); then
|
if (( 31 - 10#$day == 0 )); then
|
||||||
printf 'Have a spooky halloween!\n'
|
printf 'Have a spooky halloween!\n'
|
||||||
|
@ -15,7 +42,7 @@ elif (( 10#$month == 10 )); then
|
||||||
printf 'Only %d days left until Halloween!\n' "$(( 31 - 10#$day ))"
|
printf 'Only %d days left until Halloween!\n' "$(( 31 - 10#$day ))"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
prompt_sym=🎃
|
PS1_prompt_sym=🎃
|
||||||
elif (( 10#$month == 12 && 10#$day < 26 )); then
|
elif (( 10#$month == 12 && 10#$day < 26 )); then
|
||||||
if (( 25 - 10#$day == 0 )); then
|
if (( 25 - 10#$day == 0 )); then
|
||||||
printf 'Merry Christmas!\n'
|
printf 'Merry Christmas!\n'
|
||||||
|
@ -23,22 +50,5 @@ elif (( 10#$month == 12 && 10#$day < 26 )); then
|
||||||
printf 'Only %d days left until Christmas!\n' "$(( 25 - 10#$day ))"
|
printf 'Only %d days left until Christmas!\n' "$(( 25 - 10#$day ))"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
prompt_sym=🌲
|
PS1_prompt_sym=🌲
|
||||||
fi
|
fi
|
||||||
|
|
||||||
setup-prompt() {
|
|
||||||
if [[ -d .git ]]; then
|
|
||||||
git_branch="$(command git branch --show-current) "
|
|
||||||
else
|
|
||||||
git_branch=""
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
PROMPT_COMMAND+=(setup-prompt)
|
|
||||||
PS1='\w $git_branch'
|
|
||||||
|
|
||||||
if [[ -v SSH_CLIENT ]]; then
|
|
||||||
PS1+='${HOSTNAME-"$(hostname)"} '
|
|
||||||
fi
|
|
||||||
|
|
||||||
PS1+='${prompt_sym-λ} '
|
|
||||||
|
|
Loading…
Reference in a new issue