Skip to content

Commit

Permalink
build: change api & refactor script
Browse files Browse the repository at this point in the history
  • Loading branch information
sgoudham committed May 31, 2024
1 parent 3d79f49 commit d9a6ccc
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ dist/
pngs/
releases/
result
hl/
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ pkgs.catppuccin-cursors.mochaMauve
- [xcursorgen](https://wiki.archlinux.org/title/Xcursorgen) to generate the
cursors.
- [inkscape](https://wiki.inkscape.org/wiki/Inkscape) to convert SVGs to PNGs.
- **(Optional)** [hyprcursor](https://github.com/hyprwm/hyprcursor) to include
hyprcursor variants.
- **(Optional)** [just](https://github.com/casey/just) to easily run development
commands.
- **(Optional)** [hyprcursor](https://github.com/hyprwm/hyprcursor) to build
hyprcursor theme

### Steps

Expand All @@ -112,17 +112,15 @@ pkgs.catppuccin-cursors.mochaMauve
```

1. Run the following command(s) if you have just installed, if not then look
inside the [justfile](./justfile) to understand what commands are being run.
All of the following support the `-h` flag to enable building of then
hyprcursor theme.
inside the [justfile](./justfile) to understand what commands are being run.

```bash
just all # Build all flavor-accent variants.
just all -h # Build all flavor-accent variants with hyprcursor support
just flavor mocha # To build all variants under one single flavor.
just flavor mocha -h # To build all variants under one single flavor with hyprcursor support
just accents mocha blue # To build only the blue variant under mocha.
just accents mocha 'blue mauve peach' # To build only the blue, mauve, and peach variants under mocha.
just all_with_hyprcursor # Build all flavor-accent variants with hyprcursor support
just build mocha # To build all variants under one single flavor.
just build_with_hyprcursor mocha # To build all variants under one single flavor with hyprcursor support
just build mocha blue # To build only the blue variant under mocha.
just build mocha 'blue mauve peach' # To build only the blue, mauve, and peach variants under mocha.
```

1. Extract built cursors in `./dist` to `$HOME/.icons` or `/usr/share/icons`.
Expand Down
43 changes: 19 additions & 24 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -63,33 +63,29 @@ create_hyprcursors() {
local out_dir="$2"
local theme_name="$3"
local hypr_dir="$out_dir/hyprcursors"
local filename dir cursor_dir striped base_name symlink target cursor_dir theme_comment
local filename dir cursor_dir base_name symlink target theme_comment

[ -d "$src_dir" ] || return 1
[ -d "$out_dir" ] || mkdir -p "$out_dir"
[ -d "$hypr_dir" ] || mkdir -p "$hypr_dir"

for file in "$src_dir"/*.svg; do
filename=$(basename -- "$file")

# hyprcursor doesn't care about sizes of svgs, can skip the '_24.svg' variant with no impact
if [[ "$filename" == *_24.svg ]]; then
continue
fi

# we want to put all of the `progress_01, progress_02, etc` into the same directory of `progress`
if [[ "$filename" == *-[0-9][0-9].svg ]]; then
dir="${filename%-[0-9][0-9].svg}"
cursor_dir="$hypr_dir/$dir"
striped="${filename#"$dir"}"

[ -d "$cursor_dir" ] || mkdir -p "$cursor_dir"
cp -- "$file" "$cursor_dir"
else
dir="${filename%.svg}"
cursor_dir="$hypr_dir/$dir"

[ -d "$cursor_dir" ] || mkdir -p "$cursor_dir"

cp -- "$file" "$cursor_dir"
fi

cursor_dir="$hypr_dir/$dir"
[ -d "$cursor_dir" ] || mkdir -p "$cursor_dir"
cp -- "$file" "$cursor_dir"
done

for config in "$CONFIG_DIR"/*.hl; do
Expand All @@ -112,22 +108,21 @@ create_hyprcursors() {
cat >"$out_dir"/manifest.hl <<-EOM
name = ${theme_name%-cursors}
description = ${theme_comment#Comment=}
version = $(git show -s --format=%cd --date=format:%Y%m%d HEAD)
version = "v0.2.1" # x-release-please-version
cursors_directory = hyprcursors
EOM
}

compile_hyprcursors() {
local src_dir="$1"
local hl_dir="$1"
local out_dir="$2"
local theme_name="$(basename "$1")"
local compile_dir="$1/../theme_${theme_name%-cursors}"
local filename dir cursor_dir striped base_name symlink target cursor_dir

[ -d "$src_dir" ] || return 1
[ -d "$hl_dir" ] || return 1
[ -d "$out_dir" ] || mkdir -p "$out_dir"

hyprcursor-util -c "$src_dir" >/dev/null
hyprcursor-util -c "$hl_dir" >/dev/null
cp -a "$compile_dir/." "$out_dir/"
}

Expand All @@ -144,21 +139,16 @@ ALIASES="$SRC_DIR/cursorList"

ACCENTS="blue dark flamingo green lavender light maroon mauve peach pink red rosewater sapphire sky teal yellow"
INKSCAPE_COMMANDS=""

HYPRCURSOR=0

while getopts "f:a:vh" option; do
while getopts "f:a:h" option; do
case $option in
f)
FLAVOR="$OPTARG"
;;
a)
ACCENTS="$OPTARG"
;;
v)
DEBUG=1
echo "[DEBUG] - Debug logging enabled"
;;
h)
HYPRCURSOR=1
;;
Expand All @@ -170,6 +160,11 @@ while getopts "f:a:vh" option; do
done
echo "[INFO] - Flavor: '$FLAVOR'"
echo "[INFO] - Accent(s): '$ACCENTS'"
if [ $HYPRCURSOR -eq 1 ]; then
echo "[INFO] - Building with hyprcursor: TRUE"
else
echo "[INFO] - Building with hyprcursor: FALSE"
fi

echo "[INFO] - Generating inkscape commands..."
for accent in $ACCENTS; do
Expand All @@ -183,7 +178,7 @@ done
echo "[INFO] - Generating inkscape commands complete"

echo "[INFO] - Converting SVGs to PNGs..."
inkscape --shell <<< ${INKSCAPE_COMMANDS} &> /dev/null
inkscape --shell <<<${INKSCAPE_COMMANDS} &>/dev/null
echo "[INFO] - Converting SVGs to PNGs complete"

echo "[INFO] - Converting to x11cursor & creating aliases..."
Expand Down
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ stdenvNoCC.mkDerivation {
runHook preBuild
patchShebangs .
just all
just all_with_hyprcursor
just zip
runHook postBuild
Expand Down
22 changes: 15 additions & 7 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,25 @@ accents := "blue dark flamingo green lavender light maroon mauve peach pink red
clean:
rm -rf pngs/ hl/ dist/ releases/

# Remove all hyprcursor related files
clean_hl:
rm -rf hl/

# Zip all directories inside of "./dist"
zip:
./create_zips

# Generate a single flavor with specific accents. E.g. "build mocha 'blue'"
accents f a *flags:
./build -f {{f}} -a '{{a}}' '{{flags}}'
# Generate a single flavor with accents, defaults to all accents
build f a=accents:
./build -f {{f}} -a '{{a}}'

# Generate a single flavor with all accents
flavor f *flags:
./build -f {{f}} -a "{{accents}}" '{{flags}}'
# Generate a single flavor with accents with hyprcursor support, defaults to all accents
build_with_hyprcursor f a=accents: clean_hl
./build -f {{f}} -a '{{a}}' -h

# Generate all flavors with their accents
all *flags: clean (flavor "latte" flags) (flavor "frappe" flags) (flavor "macchiato" flags) (flavor "mocha" flags)
all: clean (build "latte") (build "frappe") (build "macchiato") (build "mocha")

# Generate all flavors with their accents with hyprcursor support
all_with_hyprcursor: clean (build_with_hyprcursor "latte") (build_with_hyprcursor "frappe") (build_with_hyprcursor "macchiato") (build_with_hyprcursor "mocha")

0 comments on commit d9a6ccc

Please sign in to comment.