mirror of
https://git.decapod.one/brethil/dotfiles
synced 2024-11-24 04:21:31 +01:00
zsh: add asciinema-switch
helps switch different asciinema profiles
This commit is contained in:
parent
d1be12fa3e
commit
0ed9e5373c
55
functions/asciinema.zsh
Normal file
55
functions/asciinema.zsh
Normal file
|
@ -0,0 +1,55 @@
|
|||
function warning {
|
||||
echo -e "$(color $YELLOW Warning:) $@" >&2
|
||||
}
|
||||
|
||||
function error {
|
||||
echo -e "$(color $RED Error:) $@" >&2
|
||||
}
|
||||
|
||||
function info {
|
||||
echo -e "$(color $GREEN Info:) $@"
|
||||
}
|
||||
|
||||
function switch-asciinema-user
|
||||
{
|
||||
local conf_dir="$HOME/.config/asciinema"
|
||||
local current_id=$(basename $(readlink -f ${conf_dir}/install-id ))
|
||||
function get_ids {
|
||||
find ${conf_dir} -name 'install-id-*' -exec basename {} \;
|
||||
}
|
||||
|
||||
if [[ $1 == "-l" || $1 == "--list" ]]; then
|
||||
echo "$(color $BOLD Available ids): (current = $(color $UNDERLINE ${current_id}))"
|
||||
for _id in $(get_ids); do
|
||||
echo " $(green ➡️) ${_id}"
|
||||
done
|
||||
return
|
||||
fi
|
||||
|
||||
local ids=$(get_ids)
|
||||
local query
|
||||
local new_id
|
||||
if [[ -n "$@" ]]; then
|
||||
query="-q $@"
|
||||
fi
|
||||
new_id=$(echo $ids| fzf --height=$(($(wc -l <<< $ids)+2)) ${query} )
|
||||
if [[ -z $new_id ]]; then
|
||||
warning "Keeping curent id ($(color $UNDERLINE ${current_id}))"
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ "$new_id" == "$current_id" ]]; then
|
||||
warning "id $new_id is already set."
|
||||
return
|
||||
fi
|
||||
|
||||
local id_file="${conf_dir}/${new_id}"
|
||||
if [[ ! -f ${id_file} ]]; then
|
||||
error "${id_file} does not exist"
|
||||
return
|
||||
fi
|
||||
|
||||
ln -sf "${id_file}" "${conf_dir}/install-id" && \
|
||||
info "Set \"$new_id\"." || \
|
||||
error "Could not set id \"$new_id\". (run with -l for a list of available profiles)"
|
||||
}
|
Loading…
Reference in New Issue
Block a user