dotfiles

A steaming hot pile of sh...ell scripts and configuration files.
Log | Files | Refs

commit 15ca93a889b0b59269925b50af884771452bd15b
parent 7b41c6e5338448e3984f54def517c8db7eee8f19
Author: Yuval Langer <yuval.langer@gmail.com>
Date:   Sat, 25 Nov 2023 13:41:56 +0200

Change shell, rename cleanup function, consolidate flag stuff.

Diffstat:
Mbin/0x0.st | 23+++++++----------------
1 file changed, 7 insertions(+), 16 deletions(-)

diff --git a/bin/0x0.st b/bin/0x0.st @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/bash set -e @@ -7,10 +7,6 @@ if [ -z "$(command -v xsel)" ] || [ -z "$(command -v curl)" ]; then exit 1 fi -# https://www.baeldung.com/linux/bash-parse-command-line-arguments - -OUR_ARGUMENTS="$(getopt -o hpsb --long help,debug,primary,secondary,clipboard -- "$@" )" - help_message () { printf "Usage: \t%s [--debug] -p / --primay @@ -28,6 +24,9 @@ Flags: # this one "$0" argument many times. } +# https://www.baeldung.com/linux/bash-parse-command-line-arguments +OUR_ARGUMENTS="$(getopt -o hpsb --long help,debug,primary,secondary,clipboard -- "$@" )" + eval set -- "$OUR_ARGUMENTS" while [ -n "$*" ]; do case "$1" in @@ -72,29 +71,21 @@ while [ -n "$*" ]; do help_message exit 1 fi + xsel_flag="$xsel_flag_primary$xsel_flag_secondary$xsel_flag_clipboard" break ;; esac done -xsel_flag="$xsel_flag_primary" -xsel_flag="$xsel_flag_secondary" -xsel_flag="$xsel_flag_clipboard" - -cleanup () { +remove_temporary_file () { if [ -n "$debug_flag" ]; then printf "\nRemoving \"%s\"\n" "$temp_file" 1>&2 fi rm "$temp_file" } -if [ "$#" -ne 1 ] && - [ "$#" -ne 2 ]; then - help_message -fi - if [ -n "$xsel_flag" ]; then - trap cleanup EXIT + trap remove_temporary_file EXIT temp_file=$(mktemp)