new script 'git-compose', allows you to easily group staged changes into several commits at once

This commit is contained in:
2024-11-17 03:44:21 -05:00
parent 287281907b
commit 03c5b9008e
4 changed files with 141 additions and 53 deletions

View File

@@ -4,83 +4,92 @@
This document contains information about the scripts I've written for this configuration. All of the scripts listed here are This document contains information about the scripts I've written for this configuration. All of the scripts listed here are
included in my nixpkgs overlay as custom packages, and these packages are declared in the configuration in the file included in my nixpkgs overlay as custom packages, and these packages are declared in the configuration in the file
`modules/home/env/userpkgs.nix` `overlay/env/userpkgs.nix`
- **icanhazip** - **icanhazip**
- **Description**: - *Description*:
- Leverages `ip` and `icanhazip.com` to return relevant IP information for the current machine. - Leverages `ip` and `icanhazip.com` to return relevant IP information for the current machine.
- **Usage**: - *Usage*:
- `icanhazip` - Returns public IP, local IP, and default gateway. - `icanhazip` - Returns public IP, local IP, and default gateway.
- `icanhazip -p` - Returns only public IP. - `icanhazip -p` - Returns only public IP.
- `icanhazip -l` - Returns only local IP. - `icanhazip -l` - Returns only local IP.
- `icanhazip -d` - Returns only default gateway. - `icanhazip -d` - Returns only default gateway.
- *Defined in*: `modules/home/scripts/commands/icanhazip.nix` - *Defined in*: `overlay/scripts/commands/icanhazip.nix`
--- ---
- **invoke** - **invoke**
- **Description**: - *Description*:
- Leverages `nix run` to run any command once. Works with arguments. - Leverages `nix run` to run any command once. Works with arguments.
- **Usage**: - *Usage*:
- `invoke <command>` - `invoke <command>`
- **Example**: - **Example**:
- `invoke hello` - `invoke hello`
- *Defined in*: `modules/home/scripts/commands/invoke.nix` - *Defined in*: `overlay/scripts/commands/invoke.nix`
--- ---
- **runbg** - **runbg**
- **Description**: - *Description*:
- Runs a command and detaches the process from the shell silently. Works with arguments. - Runs a command and detaches the process from the shell silently. Works with arguments.
- Credit to [Frost-Phoenix](https://github.com/Frost-Phoenix) for writing this script. - Credit to [Frost-Phoenix](https://github.com/Frost-Phoenix) for writing this script.
- **Usage**: - *Usage*:
- `runbg <command> <args>` - `runbg <command> <args>`
- **Example**: - **Example**:
- `runbg waybar` - `runbg waybar`
- *Defined in*: `modules/home/scripts/commands/runbg.nix` - *Defined in*: `overlay/scripts/commands/runbg.nix`
---
- **git-compose**
- *Description*:
- To be used in a git repository. Opens an interactive neovim session containing all currently uncommitted changes. Allows you to group files together and give individual commit messages to each group of files. Automatically creates commits for the file groups with the given commit messages.
- *Usage*:
- `git-compose (inside of a git repository)`
- *Defined in*: `overlay/scripts/commands/git-compose.nix`
--- ---
- **toolbelt** - **toolbelt**
- **Description**: - *Description*:
- Opens a fuzzyfinder window with some useful utilities. - Opens a fuzzyfinder window with some useful utilities.
- Meant to be used with the `Super + P` bind defined in `hyprland.nix`, and not invoked directly from the shell. - Meant to be used with the `Super + P` bind defined in `hyprland.nix`, and not invoked directly from the shell.
- *Defined in*: `modules/home/scripts/commands/toolbelt.nix` - *Defined in*: `overlay/scripts/commands/toolbelt.nix`
--- ---
- **viconf** - **viconf**
- **Description**: - *Description*:
- Searches the directory held in the `$FLAKEPATH` environment variable for a given Nix file or directory name. - Searches the directory held in the `$FLAKEPATH` environment variable for a given Nix file or directory name.
- Opens the file in Neovim, or if there are multiple matches, opens a fuzzyfinder window to allow you to choose one. - Opens the file in Neovim, or if there are multiple matches, opens a fuzzyfinder window to allow you to choose one.
- **Usage**: - *Usage*:
- `viconf <part of path or filename>` - `viconf <part of path or filename>`
- **Examples**: - **Examples**:
- `viconf hyprland` - Opens `$FLAKEPATH/modules/home/environment/hyprland.nix`. - `viconf hyprland` - Opens `$FLAKEPATH/overlay/environment/hyprland.nix`.
- `viconf sys` - Opens a fuzzyfinder window containing all Nix files in `modules/sys` and its subdirectories. - `viconf sys` - Opens a fuzzyfinder window containing all Nix files in `modules/sys` and its subdirectories.
- `viconf config` - Opens a fuzzyfinder window containing all Nix files called `config.nix`. - `viconf config` - Opens a fuzzyfinder window containing all Nix files called `config.nix`.
- `viconf scripts/def` - Opens `$FLAKEPATH/modules/home/scripts/default.nix`. - `viconf scripts/def` - Opens `$FLAKEPATH/overlay/scripts/default.nix`.
- *Defined in*: `modules/home/scripts/commands/viconf.nix` - *Defined in*: `overlay/scripts/commands/viconf.nix`
--- ---
- **vipkg** - **vipkg**
- **Description**: - *Description*:
- Searches the `pkgs` directory from the Nixpkgs GitHub repository. - Searches the `pkgs` directory from the Nixpkgs GitHub repository.
- Works almost identically to `viconf` with a few tweaks to accommodate the different directory structure. - Works almost identically to `viconf` with a few tweaks to accommodate the different directory structure.
- Useful for overriding a package's build attributes or searching for a package name. - Useful for overriding a package's build attributes or searching for a package name.
- **Usage**: - *Usage*:
- `vipkg <part of package name>` - `vipkg <part of package name>`
- **Example**: - **Example**:
- `vipkg neofetch` - Opens `nixpkgs/pkgs/tools/misc/neofetch/default.nix`. - `vipkg neofetch` - Opens `nixpkgs/pkgs/tools/misc/neofetch/default.nix`.
- *Defined in*: `modules/home/scripts/commands/vipkg.nix` - *Defined in*: `overlay/scripts/commands/vipkg.nix`
--- ---
- **fetchfromgh** - **fetchfromgh**
- **Description**: - *Description*:
- Given a username and repo name like `someuser/somerepo`, generates a full `pkgs.fetchFromGitHub` call. Uses the most recent commit. - Given a username and repo name like `someuser/somerepo`, generates a full `pkgs.fetchFromGitHub` call. Uses the most recent commit.
- **Usage**: - *Usage*:
- `fetchfromgh someuser/somerepo` - `fetchfromgh someuser/somerepo`
- **Example**: - **Example**:
- `fetchfromgh pagedMov/nixos-config` - `fetchfromgh pagedMov/nixos-config`
@@ -93,39 +102,39 @@ included in my nixpkgs overlay as custom packages, and these packages are declar
hash = "sha256-z+3E+ueSd2QNqtrbBKt8bwIfboPCXSUrGn690Hc/kl0="; hash = "sha256-z+3E+ueSd2QNqtrbBKt8bwIfboPCXSUrGn690Hc/kl0=";
}; };
``` ```
- *Defined in*: `modules/home/scripts/nix/fetchfromgh.nix` - *Defined in*: `overlay/scripts/nix/fetchfromgh.nix`
--- ---
- **garbage-collect** - **garbage-collect**
- **Description**: - *Description*:
- Runs the Nix garbage collector and also deletes all files in `.local/share/Trash`. - Runs the Nix garbage collector and also deletes all files in `.local/share/Trash`.
- **Usage**: - *Usage*:
- `garbage-collect` - Does not take any arguments. - `garbage-collect` - Does not take any arguments.
- *Defined in*: `modules/home/scripts/nix/garbage-collect.nix` - *Defined in*: `overlay/scripts/nix/garbage-collect.nix`
--- ---
- **nsp** - **nsp**
- **Description**: - *Description*:
- Simple alias for `nix-shell -p`. - Simple alias for `nix-shell -p`.
- **Usage**: - *Usage*:
- `nsp <package name>` - `nsp <package name>`
- **Example**: - **Example**:
- `nsp hello` - `nsp hello`
- *Defined in*: `modules/home/scripts/nix/nsp.nix` - *Defined in*: `overlay/scripts/nix/nsp.nix`
--- ---
- **rebuild** - **rebuild**
- **Description**: - *Description*:
- Combines `nh os switch` and `nh home switch` into a single command. - Combines `nh os switch` and `nh home switch` into a single command.
- **Usage**: - *Usage*:
- `rebuild -h` - Runs `nh home switch -c <currenthostname> $FLAKEPATH` - `rebuild -h` - Runs `nh home switch -c <currenthostname> $FLAKEPATH`
- `rebuild -s` - Runs `nh os switch -H <currenthostname> $FLAKEPATH` - `rebuild -s` - Runs `nh os switch -H <currenthostname> $FLAKEPATH`
- `rebuild -a` - Runs both of the above commands. - `rebuild -a` - Runs both of the above commands.
- Adding `n` before any flag (e.g., `rebuild -na`) performs a dry run. - Adding `n` before any flag (e.g., `rebuild -na`) performs a dry run.
- *Defined in*: `modules/home/scripts/nix/rebuild.nix` - *Defined in*: `overlay/scripts/nix/rebuild.nix`
--- ---
@@ -134,75 +143,75 @@ included in my nixpkgs overlay as custom packages, and these packages are declar
--- ---
- **chscheme** - **chscheme**
- **Description**: - *Description*:
- Opens an `fzf` menu containing all of the color schemes available in the `base16schemes` package from Nixpkgs. - Opens an `fzf` menu containing all of the color schemes available in the `base16schemes` package from Nixpkgs.
- The `fzf` preview shows the colors so you can see them in your terminal before choosing one. - The `fzf` preview shows the colors so you can see them in your terminal before choosing one.
- **Usage**: - *Usage*:
- `chscheme` - Does not take arguments. - `chscheme` - Does not take arguments.
- *Defined in*: `modules/home/scripts/wm-controls/chscheme.nix` - *Defined in*: `overlay/scripts/wm-controls/chscheme.nix`
--- ---
- **chpaper** - **chpaper**
- **Description**: - *Description*:
- Opens an `fzf` menu containing all wallpapers in `$FLAKEPATH/assets/wallpapers`. - Opens an `fzf` menu containing all wallpapers in `$FLAKEPATH/assets/wallpapers`.
- The `fzf` preview shows the image file the user is hovering over. - The `fzf` preview shows the image file the user is hovering over.
- **Usage**: - *Usage*:
- `chpaper` - Does not take arguments. - `chpaper` - Does not take arguments.
- *Defined in*: `modules/home/scripts/wm-controls/chpaper.nix` - *Defined in*: `overlay/scripts/wm-controls/chpaper.nix`
--- ---
- **keyring** - **keyring**
- **Description**: - *Description*:
- Opens an `fzf` menu containing all directories/files in `~/.password-store`. - Opens an `fzf` menu containing all directories/files in `~/.password-store`.
- Selecting an entry uses `pass -c` to copy it to the clipboard. - Selecting an entry uses `pass -c` to copy it to the clipboard.
- Temporarily pauses the clipboard history daemon to ensure the password is not added to clipboard history. - Temporarily pauses the clipboard history daemon to ensure the password is not added to clipboard history.
- Automatically clears the password from the clipboard after 10 seconds unless overwritten. - Automatically clears the password from the clipboard after 10 seconds unless overwritten.
- **Usage**: - *Usage*:
- `keyring` - Does not take arguments. - `keyring` - Does not take arguments.
- *Defined in*: `modules/home/scripts/wm-controls/keyring.nix` - *Defined in*: `overlay/scripts/wm-controls/keyring.nix`
--- ---
- **mkscreenshots** - **mkscreenshots**
- **Description**: - *Description*:
- Switches to workspace 4 (if empty) and takes screenshots showcasing the desktop environment. - Switches to workspace 4 (if empty) and takes screenshots showcasing the desktop environment.
- Saves the screenshots to `$FLAKEPATH/assets/screens`, overwriting the old ones. - Saves the screenshots to `$FLAKEPATH/assets/screens`, overwriting the old ones.
- Updates `README.md` to include the commit hash of the current screenshots. - Updates `README.md` to include the commit hash of the current screenshots.
- **Usage**: - *Usage*:
- `mkscreenshots` - Does not take arguments. Only runs if workspace 4 has no windows. - `mkscreenshots` - Does not take arguments. Only runs if workspace 4 has no windows.
- *Defined in*: `modules/home/scripts/wm-controls/mkscreenshots.nix` - *Defined in*: `overlay/scripts/wm-controls/mkscreenshots.nix`
--- ---
- **moveonscreen** - **moveonscreen**
- **Description**: - *Description*:
- Uses `hyprctl` to move the currently active floating window relative to the cursor. - Uses `hyprctl` to move the currently active floating window relative to the cursor.
- Prevents the window from moving outside the screen bounds. - Prevents the window from moving outside the screen bounds.
- Often used with `toolbelt` for smooth window movements. - Often used with `toolbelt` for smooth window movements.
- **Usage**: - *Usage*:
- `moveonscreen` - Moves the window to the cursor's position, anchored at the top-left corner. - `moveonscreen` - Moves the window to the cursor's position, anchored at the top-left corner.
- `moveonscreen --center` - Moves the window to the cursor's position, anchored at the center of the window. - `moveonscreen --center` - Moves the window to the cursor's position, anchored at the center of the window.
- *Defined in*: `modules/home/scripts/wm-controls/moveonscreen.nix` - *Defined in*: `overlay/scripts/wm-controls/moveonscreen.nix`
--- ---
- **s_check** - **s_check**
- **Description**: - *Description*:
- Tests whether `$SOUNDS_ENABLED` is set to `0` or `1`. - Tests whether `$SOUNDS_ENABLED` is set to `0` or `1`.
- Does not return anything except the status code from the test. - Does not return anything except the status code from the test.
- *Note*: This does not work as a Zsh alias for unknown reasons. - *Note*: This does not work as a Zsh alias for unknown reasons.
- **Usage**: - *Usage*:
- `s_check` - Does not take arguments. - `s_check` - Does not take arguments.
- *Defined in*: `modules/home/scripts/wm-controls/switchmon.nix` - *Defined in*: `overlay/scripts/wm-controls/switchmon.nix`
--- ---
- **switchmon** - **switchmon**
- **Description**: - *Description*:
- Uses `hyprctl` to switch focus between two monitors. - Uses `hyprctl` to switch focus between two monitors.
- Only supports setups with two monitors. - Only supports setups with two monitors.
- **Usage**: - *Usage*:
- `switchmon` - Does not take arguments. - `switchmon` - Does not take arguments.
- *Defined in*: `modules/home/scripts/wm-controls/switchmon.nix` - *Defined in*: `overlay/scripts/wm-controls/switchmon.nix`

View File

@@ -35,6 +35,7 @@ let
myScripts.moveonscreen myScripts.moveonscreen
myScripts.s_check myScripts.s_check
myScripts.switchmon myScripts.switchmon
myScripts.git-compose
]; ];
in { in {
options = { options = {

View File

@@ -10,6 +10,7 @@
# Scripts written using pkgs.writeShellApplication # Scripts written using pkgs.writeShellApplication
icanhazip = super.callPackage ./scripts/commands/icanhazip.nix { pkgs = super; }; icanhazip = super.callPackage ./scripts/commands/icanhazip.nix { pkgs = super; };
invoke = super.callPackage ./scripts/commands/invoke.nix { pkgs = super; self = root; }; invoke = super.callPackage ./scripts/commands/invoke.nix { pkgs = super; self = root; };
git-compose = super.callPackage ./scripts/commands/git-compose.nix { pkgs = super; };
runbg = super.callPackage ./scripts/commands/runbg.nix { pkgs = super; }; runbg = super.callPackage ./scripts/commands/runbg.nix { pkgs = super; };
splash = super.callPackage ./scripts/commands/splash.nix { pkgs = super; }; splash = super.callPackage ./scripts/commands/splash.nix { pkgs = super; };
toolbelt = super.callPackage ./scripts/commands/toolbelt.nix { pkgs = super; }; toolbelt = super.callPackage ./scripts/commands/toolbelt.nix { pkgs = super; };

View File

@@ -0,0 +1,77 @@
{ pkgs }:
pkgs.writeShellApplication {
name = "git-compose";
runtimeInputs = with pkgs; [
git
gawk
];
text = ''
toplevel=$(git rev-parse --show-toplevel 2>/dev/null)
if [ -z "$toplevel" ]; then
echo "You aren't in a git repository."
exit 1
fi
(
cd "$toplevel" || { echo "Failed to change to repo root"; exit 1; }
git reset
unstaged=$(git status --porcelain | awk '{print $2}') || { echo "Failed to get git status"; exit 1; }
if [ -z "$unstaged" ]; then
echo "No unstaged files found."
exit 0
fi
tmpfile=$(mktemp) || { echo "Failed to create a temporary file"; exit 1; }
trap 'rm -f "$tmpfile"' EXIT
{
echo "# Compose your commits here"
echo "#"
echo "# Format should be as follows:"
echo "# <some_commit_message>"
echo "# <file1>"
echo "# <file2>"
echo "# <file3>"
echo "#"
echo "# Groups are separated by empty lines"
echo "# Commits will be created for each group of files"
echo "# using the given commit message at the top of the group"
echo
echo "$unstaged"
} >> "$tmpfile"
nvim -c 'setfiletype gitcommit' "$tmpfile"
collecting=false
msg=""
lines=()
while IFS= read -r line; do
[[ "$line" =~ ^#[[:space:]]* ]] && continue
if [ -z "$line" ]; then
if [ -n "$msg" ] && [ ''${#lines[@]} -gt 0 ]; then
git add "''${lines[@]}"
git commit -m "$msg"
fi
collecting=false
msg=""
lines=()
elif [ "$collecting" = "false" ]; then
collecting=true
msg="$line"
else
lines+=("$line")
fi
done < "$tmpfile"
# Final cleanup
if [ -n "$msg" ] && [ ''${#lines[@]} -gt 0 ]; then
git add "''${lines[@]}"
git commit -m "$msg"
fi
)
'';
}