README.MD typo fix
Aliases - Moved to appropriately named file - Added aliases for copying git-template and prettier-template - Fix to git_push_all_changes function Nvims - Compacted the function Project Access - pnew() updated to clone remore repo or create a new one from scratch depending on options provided
This commit is contained in:
@@ -1,14 +1,19 @@
|
||||
#!/bin/sh
|
||||
|
||||
# TODO: Alias to quickly add my template .gitignore file to any location
|
||||
# TODO:
|
||||
# - Create fuzzy finder for cht.sh & tldr + system man pages + learnxinyminutes github
|
||||
|
||||
|
||||
# Quick open project files in NVIM
|
||||
op() {
|
||||
if ! command -v fzf >/dev/null; then
|
||||
echo "Install fzf to use this function."
|
||||
return 1
|
||||
return 127
|
||||
fi
|
||||
|
||||
# %T => Sort by last modified
|
||||
# @ => time displayed in seconds (since 1.1.1970)
|
||||
# %p => Directory path
|
||||
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
|
||||
@@ -16,14 +21,15 @@ op() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
cd "$project_dir" || return
|
||||
cd "$project_dir" || return 126
|
||||
nvim
|
||||
}
|
||||
|
||||
# Quick create new projects
|
||||
pnew() {
|
||||
if ! command -v fzf >/dev/null; then
|
||||
echo "Install fzf to use this function."
|
||||
return 1
|
||||
return 127
|
||||
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? ')"
|
||||
@@ -33,38 +39,41 @@ pnew() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
# FIX: User cancelling out here
|
||||
is_clone=$(printf 'yes\nno' | fzf)
|
||||
is_clone=$(printf 'no\nyes' | fzf --prompt='Clone from remote repo?')
|
||||
|
||||
# Do nothing and return if user cancelled out
|
||||
if [ "$is_clone" = "" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ "$is_clone" = "yes" ]; then
|
||||
# Clone the repo and open nvim on it
|
||||
printf "Git repo URL: " >&2
|
||||
printf "Git repo URL: "
|
||||
read -r git_url
|
||||
cd "$directory" || return
|
||||
cd "$directory" || return 126
|
||||
git clone "$git_url" || cd - >/dev/null && return
|
||||
cd "$(basename "$git_url" | cut -d '.' -f 1)" || return
|
||||
cd "$(basename "$git_url" | cut -d '.' -f 1)" || return 126
|
||||
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
|
||||
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)
|
||||
|
||||
if [ "$project_name" = "" ]; then
|
||||
echo "Cancelling..."
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ -d "$directory/$project_name" ]; then
|
||||
echo "'$directory/$project_name' already exists"
|
||||
if [ -d "$directory/$project_name" ] || [ -e "$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
|
||||
if [ ! -d "$directory/$project_name" ] && [ ! -e "$directory/$project_name" ]; then
|
||||
mkdir -p "$directory/$project_name" || return 126
|
||||
fi
|
||||
|
||||
cd "$directory/$project_name" || return 126
|
||||
git init || return 126
|
||||
fi
|
||||
|
||||
nvim
|
||||
|
||||
Reference in New Issue
Block a user