#!/bin/sh # 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 | dmenu -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 st else while [ -z "$choice" ] do choice=$(printf 'create\nclone\ncancel' | dmenu -p "New repository at ~/git/$dest?") done case "$choice" in "create") mkdir -p "$dest_path" cd "$dest_path" || exit 1 git init exec st ;; "clone") while [ -z "$remote_choice" ] do remote_choice=$(printf 'github.com\ncacharle.xyz\nother' | dmenu -p "Remote location") done case "$remote_choice" in "github.com") prefix='git@github.com:cacharle/' ;; "cacharle.xyz") prefix='git@cacharle.xyz:/srv/git/' ;; "other") ;; esac url="$prefix$(echo "$dest" | dmenu -p "Enter repository url: $prefix")" st -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