Compare commits
4 Commits
3c981a5658
...
086e4d6626
Author | SHA1 | Date | |
---|---|---|---|
![]() |
086e4d6626 | ||
![]() |
ea8fbd0c22 | ||
![]() |
eaa4034210 | ||
![]() |
acb9c4d7b4 |
20
Makefile
Normal file
20
Makefile
Normal file
@@ -0,0 +1,20 @@
|
||||
PREFIX ?= $(HOME)/.local
|
||||
BINDIR := $(PREFIX)/bin
|
||||
FISH_COMPDIR := $(PREFIX)/share/fish/vendor_completions.d
|
||||
|
||||
chot := bin/chot
|
||||
fish_completion := completions/chot.fish
|
||||
|
||||
install:
|
||||
@echo "Installing chot to $(BINDIR)"
|
||||
install -d $(BINDIR)
|
||||
install -m 755 $(chot) $(BINDIR)/chot
|
||||
@echo "Installing fish completion to $(FISH_COMPDIR)"
|
||||
install -d $(FISH_COMPDIR)
|
||||
install -m 644 $(fish_completion) $(FISH_COMPDIR)/chot.fish
|
||||
|
||||
uninstall:
|
||||
rm -f $(BINDIR)/chot
|
||||
rm -f $(FISH_COMPDIR)/chot.fish
|
||||
|
||||
.PHONY: install uninstall
|
54
README.md
Normal file
54
README.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# chot
|
||||
|
||||
**`chot` (ちょっと)** - pronounced /cho-tto/ - is a minimalist launcher for running or editing ephemeral, one-off scripts.
|
||||
|
||||
It lets you keep messy glue code, experimental snippets, or temporary scripts in a central place — and run or edit them with a simple command.
|
||||
|
||||
## Features
|
||||
|
||||
- `chot foo` runs a script called `foo`
|
||||
- `chot edit foo` opens the script in `$EDITOR`
|
||||
- `help` and `--help` are supported
|
||||
- Script directory is configurable and auto-created
|
||||
- Fish shell completion included
|
||||
|
||||
## Usage
|
||||
|
||||
```sh
|
||||
chot foo # Runs the script named 'foo'
|
||||
chot edit foo # Opens 'foo' in your $EDITOR
|
||||
chot help # Show help
|
||||
```
|
||||
|
||||
## Script Directory Resolution
|
||||
|
||||
chot stores and looks for scripts in this order:
|
||||
|
||||
1. `$CHOT_SCRIPT` (if set)
|
||||
2. `$XDG_DATA_HOME/chot/scripts` (if `$XDG_DATA_HOME` is set)
|
||||
3. `~/.local/share/chot/scripts`
|
||||
|
||||
If the directory does not exist, it will be created automatically the first time you run or edit a script.
|
||||
|
||||
💡 **Note:** We intentionally delay creating this directory until it's needed — just viewing `--help` shouldn't modify your filesystem.
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
make install
|
||||
```
|
||||
|
||||
This will install:
|
||||
|
||||
- `bin/chot` to `~/.local/bin/`
|
||||
- Fish shell completion to the appropriate directory
|
||||
|
||||
## Uninstallation
|
||||
|
||||
```sh
|
||||
make uninstall
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
74
bin/chot
Normal file
74
bin/chot
Normal file
@@ -0,0 +1,74 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
CHOT_SCRIPT="${CHOT_SCRIPT:-${XDG_DATA_HOME:-$HOME/.local/share}/chot/scripts}"
|
||||
EDITOR="${EDITOR:-vi}"
|
||||
|
||||
usage() {
|
||||
echo "Usage: chot [edit] <script-name> [args...]"
|
||||
echo
|
||||
echo " Run or edit one-off scripts stored in a user directory."
|
||||
echo
|
||||
echo " run <script> Run the script (default)"
|
||||
echo " edit <script> Edit the script in \$EDITOR"
|
||||
echo " help, --help Show this help message"
|
||||
echo
|
||||
echo "Scripts are stored in \$CHOT_SCRIPT, or by default:"
|
||||
echo " \$XDG_DATA_HOME/chot/scripts or ~/.local/share/chot/scripts"
|
||||
echo "The directory is created automatically when needed."
|
||||
echo
|
||||
[ -n "${CHOT_SCRIPT:-}" ] && echo "Current script directory: $CHOT_SCRIPT"
|
||||
|
||||
exit "${1:-1}"
|
||||
}
|
||||
|
||||
# Intercept --help or help before evaluating $CHOT_SCRIPT
|
||||
# (We don't want to mkdir or mutate the environment just to show help)
|
||||
if [ "${1:-}" = "--help" ] || [ "${1:-}" = "help" ]; then
|
||||
usage 0
|
||||
fi
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ ! -d "$CHOT_SCRIPT" ]; then
|
||||
mkdir -p "$CHOT_SCRIPT"
|
||||
echo "Created script directory: $CHOT_SCRIPT" >&2
|
||||
fi
|
||||
|
||||
action="run"
|
||||
if [ "$1" = "edit" ]; then
|
||||
action="edit"
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "Error: missing script name"
|
||||
usage
|
||||
fi
|
||||
|
||||
name="$1"
|
||||
script="$CHOT_SCRIPT/$name"
|
||||
shift || true # shift off the script name; remaining args go to the script
|
||||
|
||||
case "$action" in
|
||||
run)
|
||||
if [ ! -f "$script" ]; then
|
||||
echo "No such script: $script"
|
||||
echo "Try 'chot edit <name>' to create it,"
|
||||
echo "or check CHOT_SCRIPT directory: $CHOT_SCRIPT"
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -x "$script" ]; then
|
||||
chmod +x "$script"
|
||||
fi
|
||||
exec "$script" "$@"
|
||||
;;
|
||||
edit)
|
||||
exec "$EDITOR" "$script"
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
26
completions/chot.fish
Normal file
26
completions/chot.fish
Normal file
@@ -0,0 +1,26 @@
|
||||
function __chot_script_dir
|
||||
set -l default (string replace -r '/$' '' $XDG_DATA_HOME)
|
||||
if test -z "$default"
|
||||
set default "$HOME/.local/share"
|
||||
end
|
||||
set -l chotdir (string replace -r '/$' '' $CHOT_SCRIPT)
|
||||
if test -z "$chotdir"
|
||||
set chotdir "$default/chot/scripts"
|
||||
end
|
||||
echo $chotdir
|
||||
end
|
||||
|
||||
function __chot_list_scripts
|
||||
set -l dir (__chot_script_dir)
|
||||
if test -d $dir
|
||||
for f in $dir/*
|
||||
if test -f $f
|
||||
basename $f
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
complete -c chot -n '__fish_use_subcommand' --no-files -f -a 'edit help'
|
||||
complete -c chot -n '__fish_seen_subcommand_from edit' --no-files -a '(__chot_list_scripts)'
|
||||
complete -c chot -n 'not __fish_seen_subcommand_from edit' --no-files -a '(__chot_list_scripts)'
|
Reference in New Issue
Block a user