#!/usr/bin/bash command -v rofi && menu_exec='rofi -dmenu' || menu_exec='dmenu' # shellcheck disable=SC2088 # (tile does not expand in single quote) dest=$( find ~/git -mindepth 1 -maxdepth 1 -printf '%A@\t%f\n' | sort -r | cut -f 2 | cat - <(echo ../snippets) | $menu_exec -l 10 -p '~/git/' ) [ -z "$dest" ] && exit 1 dest_path="$HOME/git/$dest" if cd "$dest_path" 2> /dev/null then touch "$dest_path" exec "$TERMINAL" else while [ -z "$choice" ] do choice=$(printf 'create\nclone\ncancel' | $menu_exec -p "New repository at ~/git/$dest?") done case "$choice" in "create") mkdir -p "$dest_path" cd "$dest_path" || exit 1 git init exec "$TERMINAL" ;; "clone") while [ -z "$remote_choice" ] do remote_choice=$(printf 'home\ngithub.com\ncacharle.xyz\nclipboard\nother' | $menu_exec -p "Remote location") done case "$remote_choice" in home) prefix='git@home-nuc:' ;; github.com) prefix='git@github.com:cacharle/' ;; cacharle.xyz) prefix='git@cacharle.xyz:/srv/git/' ;; clipboard) dest="$(xclip -selection clipboard -o)" ;; other) ;; esac url="$prefix$(echo "$dest" | $menu_exec -p "Enter repository url: $prefix")" "$TERMINAL" -e /bin/sh -c "git clone --recursive '$url' '$dest_path' && cd '$dest_path' && exec $SHELL" || notify-send -u critical "Could not clone $url in $dest_path" && exit 1 ;; "cancel") exit ;; *) exit 1 ;; esac fi