From d6dbc20746114889a2d4dada45fd4e6d16b81749 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Thu, 14 Jan 2021 01:10:01 +0800 Subject: [PATCH] Improve my custom scripts --- bin/choose-emoji-menu | 4 ++-- bin/generate-gitignore | 25 +++++++++++++++++++++++++ bin/init-template | 12 ++++++++++++ bin/ocr | 3 +-- 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100755 bin/generate-gitignore create mode 100755 bin/init-template diff --git a/bin/choose-emoji-menu b/bin/choose-emoji-menu index 0576702..644b191 100755 --- a/bin/choose-emoji-menu +++ b/bin/choose-emoji-menu @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash # Simply create a universal emoji selection list. # The emoji list should be the following file: @@ -12,7 +12,7 @@ # * rofi - Version: 1.5.4 # * xclip - version 0.13 -emoji_file="${XDG_DATA_HOME:-HOME/.local/share}/emoji-list.txt" +emoji_file="${XDG_DATA_HOME:-$HOME/.local/share}/emoji-list.txt" if [[ ! -f $emoji_file ]]; then notify-send "Downloading the emoji data file." wget --output-document "$emoji_file" https://unicode.org/Public/emoji/13.0/emoji-test.txt diff --git a/bin/generate-gitignore b/bin/generate-gitignore new file mode 100755 index 0000000..8129a49 --- /dev/null +++ b/bin/generate-gitignore @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# A quick command line interface for creating a gitignore with the API from https://gitignore.io. +# This script comes with a simple caching to avoid creating too much requests. + +# Dependencies: +# * bash +# * curl +# * fzf +# * paste +# * xargs + +set -eo pipefail + +CACHE_FILE="${XDG_CACHE_DIR:-$HOME/.cache}/gitignore-io.langs.json" + +# Check if the language list is downloaded for the last hour (3600 seconds). +if [ ! -e $CACHE_FILE ] || test $(expr $(date "+%s") - $(date -r $CACHE_FILE "+%s")) -gt 3600 +then + curl --silent --location --output $CACHE_FILE "https://gitignore.io/api/list?format=json" +fi + +KEYS=$(jq 'keys | .[] | @text' --raw-output $CACHE_FILE | fzf --multi | while read lang; do echo " .[\"$lang\"].contents"; done | paste -s -d ',') + +jq "$KEYS" --raw-output $CACHE_FILE diff --git a/bin/init-template b/bin/init-template new file mode 100755 index 0000000..7328046 --- /dev/null +++ b/bin/init-template @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -eo pipefail + +TEMPLATES_DIR="$HOME/templates" + +while [[ ! -a "$TEMPLATES_DIR/$TEMPLATE/cookiecutter.json" ]] +do + TEMPLATE="$TEMPLATE/$(ls "$TEMPLATES_DIR/$TEMPLATE" | fzf)" +done + +cookiecutter "$TEMPLATES_DIR/$TEMPLATE" diff --git a/bin/ocr b/bin/ocr index 0ab5fe1..15bb26d 100755 --- a/bin/ocr +++ b/bin/ocr @@ -7,7 +7,6 @@ # * leptonica-1.79.0 # * The Tesseract English data # * Image libraries (e.g., `libgif`, `libwebp`) -# * ImageWorsener 1.3.3 # * xclip - version 0.13 # * maim - version 5.6.3 @@ -16,5 +15,5 @@ set -o pipefail notify-send "Select a region for the OCR" -maim --select --hidecursor | imagew - -outfmt png -w x5 - | tesseract - stdout +maim --select --hidecursor | magick mogrify -modulate 100,0 -resize 400% png:- | tesseract - stdout