Something went wrong. Try again.
Small (but incredibly useful!) scripts and utilities that don't need their own repo.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354#!/usr/bin/env nu# SPDX-License-Identifier: AGPL-3.0-only# Copyright (c) 2026 MatrixFurry <matrix@matrixfurry.com>
const self = path self | path expandconst templates_dir = $self | path join ../../resources/gitignore/
# Quickly and easily create or update `gitignore` files from predefined templates.export def main [ --replace (-r) # Overwrite the exiting gitignore rather than appending to it --global (-g) # Create a global ignore file at `~/.config/git/ignore`] { let output_path: path = if $global { mkdir ~/.config/git "~/.config/git/ignore" | path expand } else { pwd | path join .gitignore }
let op = if ($output_path | path exists) { if $replace {$"(ansi red)Replaced"} else {$"(ansi yellow)Appended(ansi reset) to"} } else { $"(ansi green)Created" }
# TODO: add global to display name or color code let templates = ls -f $templates_dir | append (ls -f ($templates_dir + "/Global")) | where type == file | get name
let selected_templates = $templates | input list -mf -s 'smart' -d {|| path parse | get stem} $"Use (ansi blue)<Tab>(ansi reset) to select templates, then (ansi blue)<Return>(ansi reset) to create"
$selected_templates | each {|path| let name = $path | path parse | get stem
$"### ($name) template\n(open --raw $path)" } | str join "\n" | if $replace { save -f $output_path } else { save -a $output_path }
print $"($op)(ansi reset) gitignore at (ansi blue)($output_path)(ansi reset) with the following templates:" $selected_templates | each {|| $"- (ansi cyan)($in | path parse | get stem)(ansi reset)"} | str join "\n" | print}