48 lines
1.1 KiB
Bash
48 lines
1.1 KiB
Bash
# Install zsh-async if it’s not present
|
||
if [[ ! -a ~/.zsh-async ]]; then
|
||
git clone -b ‘v1.5.2’ git@github.com:mafredri/zsh-async ~/.zsh-async
|
||
fi
|
||
|
||
source ~/.zsh-async/async.zsh
|
||
|
||
|
||
# Initialize zsh-async
|
||
async_init
|
||
|
||
# Start a worker that will report job completion
|
||
async_start_worker vagrant_prompt_worker -n
|
||
|
||
# Wrap vagrant status in a function, so we can pass in the working directory
|
||
vagrant_status() {
|
||
VAGRANT_CWD=$1 vagrant status
|
||
}
|
||
|
||
# Define a function to process the result of the job
|
||
completed_callback() {
|
||
local output=$@
|
||
if [[ $output =~ 'running' ]]; then
|
||
H_PROMPT_VAGRANT_UP='vagrant up'
|
||
else
|
||
H_PROMPT_VAGRANT_UP=''
|
||
fi
|
||
async_job vagrant_prompt_worker vagrant_status $(pwd)
|
||
}
|
||
|
||
# Register our callback function to run when the job completes
|
||
async_register_callback vagrant_prompt_worker completed_callback
|
||
|
||
# Start the job
|
||
async_job vagrant_prompt_worker vagrant_status $(pwd)
|
||
|
||
|
||
# add our variable to our prompt.
|
||
TMOUT=1
|
||
TRAPALRM() { zle reset-prompt }
|
||
username="%n"
|
||
path_string="%3c"
|
||
precmd() {
|
||
date_string=$(date +'%Y-%m-%d %H:%M:%S')
|
||
}
|
||
PROMPT='${date_string} ${username} ${path_string} $H_PROMPT_VAGRANT_UP
|
||
» '
|