Files
dotfiles/.config/zsh/autoload/git-submodule-rm
druckdev 4fedae1a4c zsh:autoload:*: Add shebang & remove vim-modeline
By adding a shebang to the scripts they can be executed directly without
an interactive shell. The shebang also makes vims modeline that only set
the filetype obsolete.
2021-07-10 00:59:25 +02:00

33 lines
809 B
Bash
Executable File

#!/usr/bin/zsh
## Author: druckdev
## Created: 2020-09-13
##
## Completely remove a git submodule.
# Exit if not in git repo
local toplevel="$(git rev-parse --show-toplevel)" || return
# Exit if no arguements were given
[[ $# -gt 0 ]] || return
local separator=""
for arg in "$@"; do
printf "$separator"
# argument relative from git toplevel
local arg_from_git="${${arg:A}##$toplevel/}"
# argument has to exist
[[ -e "$arg" ]] || continue
# argument has to exist in repo
[[ -e "$toplevel/$arg_from_git" ]] || continue
# has to be a submodule
[[ -e "$toplevel/.git/modules/$arg_from_git" ]] || continue
git submodule deinit -f "$arg"
echo "command rm -rf \"$toplevel/.git/modules/$arg_from_git\""
command rm -rf "$toplevel/.git/modules/$arg_from_git"
git rm -f "$arg"
separator="\n"
done