1
0
mirror of https://git.decapod.one/brethil/dotfiles synced 2024-12-22 23:31:32 +01:00
dotfiles/functions/asciinema.zsh

Failed to ignore revisions in .git-blame-ignore-revs.

44 lines
1.1 KiB
Bash
Raw Normal View History

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