added releaser script added help menu added gallery for different directory
sophuwu sophie@sophuwu.com
Sat, 01 Nov 2025 03:31:56 +0100
8 files changed,
185 insertions(+),
49 deletions(-)
D
docs/sketch.1
@@ -1,49 +0,0 @@
-.TH SKETCH 1 "October 2023" "Version 1.1.0" "User Commands" -.SH NAME -sketch \- Terminal image viewer - -.SH SYNOPSIS -.B sketch -[\fIoptions\fR] \fIimage_files\fR... - -.SH DESCRIPTION -.B sketch -is a terminal image viewer that scales images to fit in the terminal while maintaining the aspect ratio. - -.SH OPTIONS -.TP -.B \-h, \-\-help -Show help message and exit. - -.TP -.B \-v, \-\-version -Show version information and exit. - -.TP -.B \-n, [0\<n\<10] -Adjust the scaling of the image. Where n is between 1 and 9, for 10% and 90% scaling, respectively. Default is 100%. - -.SH EXAMPLES -.TP -View an image in the terminal: -.B sketch -image.png - -.TP -View multiple images in the terminal: -.B sketch -image1.png image2.jpg - -.TP -Adjust the scaling of the image: -.B sketch \-s 5 -image.png - -.SH AUTHOR -Sophie Kisiel <sophie@skisiel.com> - -.SH LICENSE -MIT License - -.SH SEE ALSO -.BR img (1)
M
main.go
→
src/main.go
@@ -102,10 +102,40 @@ }
var scaleFlag = regexp.MustCompile(`-[0-9]+`) +func init() { + for _, arg := range os.Args[1:] { + if arg == "-h" || arg == "--help" { + fmt.Println("Usage: imgcat [options] [image files]") + fmt.Println("Options:") + fmt.Println(" -h, --help Show this help message") + fmt.Println(" -sN Set scale to N/10 (e.g., -s8 sets scale to 0.8)") + fmt.Println() + fmt.Println("To use interactive gallery mode, run without any arguments.\nOr with a directory as the only argument.") + os.Exit(0) + } + if arg == "--version" { + fmt.Printf("sketch: %s\nversion: %s\n", os.Args[0], SKETCH_VERSION) + os.Exit(0) + } + } +} + func main() { if len(os.Args) == 1 { gallery() return + } + if len(os.Args) == 2 { + st, err := os.Stat(os.Args[1]) + if err == nil && st.IsDir() { + err = os.Chdir(os.Args[1]) + if err != nil { + fmt.Fprintln(os.Stderr, "fatal: could not change directory") + os.Exit(1) + } + gallery() + return + } } var img Immg img.Scale = 1
A
releaser/Makefile
@@ -0,0 +1,29 @@
+# Makefile for building the deb package +NAME = sketch +# Versioning +# run `date '+%Y.%m.%d' to set the version` +VERSION = $(shell date '+%Y.%m.%d') + +START_DIR = $(shell pwd) +SRC_DIR = ../src +BUILD_DIR = ./build/$(VERSION) + +ifeq ($(shell command -v upx), ) +UPX = echo "UPX not found, skipping compression" +else +UPX = upx --lzma --best $(NAME) +endif + + +FLAGS = + +defualt: $(SRC_DIR)/ sketch.1 + mkdir -p $(BUILD_DIR) + cp -r $(SRC_DIR) $(BUILD_DIR) + sed -e 's/{{ Version }}/$(VERSION)/g' sketch.1 > ./$(BUILD_DIR)/sketch.1 + sed -e 's/{{ Version }}/$(VERSION)/g' ../src/version.go > ./$(BUILD_DIR)/src/version.go + VERSION=$(VERSION) TARGET="amd64" ./build.sh + VERSION=$(VERSION) TARGET="arm64" ./build.sh + +clean: + @echo "unimplemented"
A
releaser/build.sh
@@ -0,0 +1,22 @@
+#!/bin/bash +command -v upx +doUpx="$?" + +set -e +[[ "$TARGET" == "amd64" || "$TARGET" == "arm64" ]] || exit 1 +[[ "$VERSION" == "$(date +%Y.%m.%d)" ]] || exit 1 +START_DIR=$(pwd) +BUILD_DIR="$START_DIR/build/$VERSION" +SRC_DIR="$BUILD_DIR/src" +BUILD_DIR="$BUILD_DIR/$TARGET" +BIN_OUT="$BUILD_DIR/sketch" + +mkdir -p $BUILD_DIR + +sed -e "s/{{ Version }}/$VERSION/g" "$START_DIR/nfpm.yaml" | sed -e "s/{{ Target }}/$TARGET/g" > "$BUILD_DIR/nfpm.yaml" +cd "$BUILD_DIR" +GOOS=linux GOARCH=$TARGET go build -ldflags "-w -s" -o "$BIN_OUT" "$SRC_DIR" +if [[ $doUpx == "0" ]]; then + upx --best --lzma "$BIN_OUT" +fi +nfpm package --packager deb --config nfpm.yaml
A
releaser/nfpm.yaml
@@ -0,0 +1,31 @@
+name: "sketch" +arch: "{{ Target }}" +platform: "linux" +version: "{{ Version }}" +section: "default" +priority: "extra" +replaces: +provides: +depends: +recommends: +suggests: +conflicts: +maintainer: "sophuwu <sophie@sophuwu.com>" +description: | + Terminal image viewer. Scales the image to fit in the terminal; maintaining aspect ratio. + Features: + - View images in your terminal + - Show as many images as you want at once + - Images always scale to fit the terminal size + - Supports png and jpg + - Adjustable scaling with flags +vendor: "sophuwu.com" +homepage: "https://git.sophuwu.com/sketch" +license: "MIT" +changelog: "" +contents: +- src: ./sketch + dst: /usr/bin/sketch +- src: ../sketch.1 + dst: /usr/share/man/man1/sketch.1 +overrides:
A
releaser/sketch.1
@@ -0,0 +1,69 @@
+.TH SKETCH 1 "October 2023" "Version {{ Version }}" "User Commands" +.SH NAME +sketch \- Terminal image viewer + +.SH SYNOPSIS +.B sketch +[\fIoptions\fR] \fIimage_files\fR... + +.SH DESCRIPTION +.B sketch +is a terminal image viewer that scales images to fit in the terminal while +maintaining the aspect ratio. The program has an interactive mode and +a command line mode. +.sp +To use interactive mode in the current directory, run the command without any +arguments. If you want to view images in a different directory, you can pass +the directory path as an argument. +.sp +.B sketch +.sp +.B sketch /path/to/directory +.sp +In interactive mode, sketch will display images in the terminal one at a time. +You can navigate through the images using the keybinding shown in the +interface. Press 'q' to exit the program. +.sp +.B Command line mode +.sp +To use command line mode, run the command with the paths to images as arguments. +.sp +.B sketch image1.png image2.jpg ~/Pictures/*.png +.sp +In command line mode, sketch will print each image to the screen one after +another. After displaying all images, the program will exit. + +.SH OPTIONS +.TP +.B \-h, \-\-help +Show help message and exit. + +.TP +.B \-n, [0\<n\<10] +Adjust the scaling of the image. Where n is between 1 and 9, for 10% and 90% scaling, +respectively. Default is 100%. + +.SH EXAMPLES +.TP +View an image in the terminal: +.B sketch +image.png + +.TP +View multiple images in the terminal: +.B sketch +image1.png image2.jpg + +.TP +Adjust the scaling of the image: +.B sketch \-s 5 +image.png + +.SH AUTHOR +Sophie Kisiel <sophie@skisiel.com> + +.SH LICENSE +MIT License + +.SH SEE ALSO +.BR img (1)