automate/zsh_async-example.sh

48 lines
1.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Install zsh-async if its 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
» '