mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 06:12:34 +00:00
Added mkcd
This commit is contained in:
12
scripts/.local/scripts/mkcd
Executable file
12
scripts/.local/scripts/mkcd
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Createsa directory then `cd`'s into the directory
|
||||
|
||||
set -e
|
||||
|
||||
dir="$1"
|
||||
|
||||
test -n "${dir}" || echo "usage: mkcd <dir>" && exit 1
|
||||
|
||||
mkdir "${dir}"
|
||||
cd "${dir}"
|
||||
@@ -8,21 +8,19 @@ test ! -n "${SCRIPTS}" && echo "SCRIPTS not set" && exit 1;
|
||||
# fallback to check if the name arg ${1} exists, if not show usage text.
|
||||
test ! -n "${1}" && \
|
||||
echo "usage: newscript <name> <optional: shell>" && \
|
||||
echo "shell defaults to `sh` if not supplied" && \
|
||||
echo "shell defaults to sh if not supplied" && \
|
||||
exit 1;
|
||||
|
||||
path="${SCRIPTS}/${1}"
|
||||
shell="${2:-sh}"
|
||||
|
||||
if [ -e "${path}" ]; then
|
||||
read -p "${1} already exists. Edit? " yes
|
||||
case "${yes}" in
|
||||
y|yes|yep|yeppers|yeah|ok|okay) exec vim "${path}"
|
||||
esac
|
||||
exit 0
|
||||
echo "Already exists try:"
|
||||
echo "vi ${path}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf "#!/bin/${shell}"\n\n" > "${path}"
|
||||
printf "#!/bin/%s\n\n" "${shell}" > "${path}"
|
||||
chmod +x "${path}"
|
||||
exec vim +2 "${path}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user