summary refs log tree commit diff
path: root/dot_config/zsh/functions
diff options
context:
space:
mode:
authorAlen <alen@dotfiles.xyz>2023-09-26 00:04:07 +0400
committerAlen <alen@dotfiles.xyz>2023-09-26 00:04:07 +0400
commitbb3cfbc180e98fa2b8cb92795492d74c96b5d465 (patch)
treef15893d0d381fde0d983630191bd8065495fac08 /dot_config/zsh/functions
parent7ecfc06316c905ab90763a5473d4aa04e85b59e1 (diff)
Add giti function
Diffstat (limited to 'dot_config/zsh/functions')
-rw-r--r--dot_config/zsh/functions/giti27
1 files changed, 27 insertions, 0 deletions
diff --git a/dot_config/zsh/functions/giti b/dot_config/zsh/functions/giti
new file mode 100644
index 0000000..ee0f4ec
--- /dev/null
+++ b/dot_config/zsh/functions/giti
@@ -0,0 +1,27 @@
+#!/usr/bin/env zsh
+
+emulate -L zsh
+
+if [[ ${1} == '--help' || ${1} == '-h' || ${1} == '' ]]; then
+    echo "Usage: ${0} [--help|-h] [reference]"
+    return 0
+fi
+
+if [[ -f .gitignore ]]; then
+    echo '.gitignore already exists'
+    return 1
+fi
+
+local TEMP="$(mktemp)"
+if curl --fail --silent "https://raw.githubusercontent.com/github/gitignore/main/${1}.gitignore" > "${TEMP}"; then
+   mv "${TEMP}" ".gitignore"
+elif curl --fail --silent "https://raw.githubusercontent.com/github/gitignore/main/${(C)1}.gitignore" > "${TEMP}"; then
+    mv "${TEMP}" ".gitignore"
+else
+    echo "Could not get ${1}"
+    return 2
+fi
+
+# Uncomment things I generally prefer uncommented
+sed -i -E 's% *# *(.idea/|poetry.lock|Pipfile.lock|.python-version|pdm.lock)%\1%g' ".gitignore"
+echo ".gitignore created"