aboutsummaryrefslogtreecommitdiff
path: root/local/bin/project-open
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-02-24 17:07:33 +0100
committerCharles Cabergs <me@cacharle.xyz>2021-02-24 17:07:33 +0100
commit468a789dbc4b1928c035d8590895efc533520a27 (patch)
tree74cb056c37eaa50cd50491a7665608488ed4feb1 /local/bin/project-open
parentf9883d2c3b3699d91e98feeffd7eece546f7c57e (diff)
downloaddotfiles-468a789dbc4b1928c035d8590895efc533520a27.tar.gz
dotfiles-468a789dbc4b1928c035d8590895efc533520a27.tar.bz2
dotfiles-468a789dbc4b1928c035d8590895efc533520a27.zip
Updated file tree to match XDG base directory specification
Diffstat (limited to 'local/bin/project-open')
-rwxr-xr-xlocal/bin/project-open53
1 files changed, 53 insertions, 0 deletions
diff --git a/local/bin/project-open b/local/bin/project-open
new file mode 100755
index 0000000..adb27a4
--- /dev/null
+++ b/local/bin/project-open
@@ -0,0 +1,53 @@
+#!/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\nclipboard\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/' ;;
+ clipboard) dest="$(xclip -selection clipboard -o)" ;;
+ 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