Files
dev_prod/10x_project_access.sh
Pratik Tripathy 1723bf8084 Project Access
- Made more POSIX compliant
- pnew: Now accepts a remote git repo
- pnew: Creates git repo on new (not git) projects

Aliases
- Dev aliases moved to this repo instead of dotfiles
- Create aliases when the underlying programs are installed
- Alias to copy my template .gitignore to current directory
2024-03-03 00:22:19 +05:30

72 lines
2.2 KiB
Bash
Executable File

#!/bin/sh
# TODO: Alias to quickly add my template .gitignore file to any location
# - Create fuzzy finder for cht.sh & tldr + system man pages + learnxinyminutes github
op() {
if ! command -v fzf >/dev/null; then
echo "Install fzf to use this function."
return 1
fi
project_dir="$(find -L ~/Code -mindepth 2 -maxdepth 2 -not -path '*/.*' -printf "%T@ %p\n" | sort -nr | cut -d ' ' -f 2- | fzf --prompt='Select a project: ')"
# Do nothing and return if user cancelled out
if [ "$project_dir" = "" ]; then
return 0
fi
cd "$project_dir" || return
nvim
}
pnew() {
if ! command -v fzf >/dev/null; then
echo "Install fzf to use this function."
return 1
fi
directory="$(find -L ~/Code/ -mindepth 1 -maxdepth 1 -not -path '*/.*' -type d | sed '/Squbix\|KeepWorks\|Supra/d' | sort | fzf --prompt='Creating new project. In which directory? ')"
# Do nothing and return if user cancelled out
if [ "$directory" = "" ]; then
return 0
fi
# FIX: User cancelling out here
is_clone=$(printf 'yes\nno' | fzf)
if [ "$is_clone" = "yes" ]; then
# Clone the repo and open nvim on it
printf "Git repo URL: " >&2
read -r git_url
cd "$directory" || return
git clone "$git_url" || cd - >/dev/null && return
cd "$(basename "$git_url" | cut -d '.' -f 1)" || return
else
# Loop until user provides a valid directory name or cancels out
while [ -d "$directory/$project_name" ]; do
if [ "$1" != "" ]; then
project_name="$1"
else
project_name=$(find -L "$directory" -mindepth 1 -maxdepth 1 -not -path '*/.*' -type d | fzf --print-query -e +i --prompt='Project name (AVOID EXISTING ONES BELOW): ' | head -1)
fi
if [ "$project_name" = "" ]; then
echo "Cancelling..."
return 0
fi
if [ -d "$directory/$project_name" ]; then
echo "'$directory/$project_name' already exists"
fi
done
[ -d "$directory/$project_name" ] || mkdir -p "$directory/$project_name" || return
cd "$directory/$project_name" || return
git init || return
fi
nvim
}