1
0
mirror of https://git.decapod.one/brethil/dotfiles synced 2024-11-24 12:31:31 +01:00
dotfiles/functions/asciinema.zsh
2024-03-01 11:25:11 +01:00

44 lines
1.1 KiB
Bash

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
yellow "Keeping curent id ($(color $UNDERLINE ${current_id}))"
return
fi
if [[ "$new_id" == "$current_id" ]]; then
yellow "id $new_id is already set."
return
fi
local id_file="${conf_dir}/${new_id}"
if [[ ! -f ${id_file} ]]; then
red "${id_file} does not exist"
return
fi
ln -sf "${id_file}" "${conf_dir}/install-id" && \
green "Set \"$new_id\"." || \
red "Could not set id \"$new_id\". (run with -l for a list of available profiles)"
}