1
0
Fork 0

Zsh functions: set options for better error handling

This commit is contained in:
tastytea 2022-04-03 05:47:50 +02:00
parent cf620b0642
commit 83ff053395
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM
8 changed files with 16 additions and 0 deletions

View File

@ -4,6 +4,8 @@
# https://tintin.mudhalla.net/info/256color/
# https://gist.github.com/Prakasaka/219fe5695beeb4d6311583e79933a009
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
function _ansi-colors_8()
{
local title="${1}"

View File

@ -1,6 +1,8 @@
#!/usr/bin/env zsh
# Compare 2 Btrfs snapshots
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
if [[ ${ARGC} -lt 2 ]]; then
print -u 2 "Usage: ${0} <old> <new>"
return 1

View File

@ -7,6 +7,8 @@
# export CATOPEN="highlight --force --out-format=truecolor --stdout %s"
# alias cat='cat-highlight'
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
# Check if we are in a terminal and a highlighter is defined
if [[ -t 1 ]] && [[ -n "${CATOPEN}" || -n "${LESSOPEN}" ]]; then
if [[ -z "${CATOPEN}" ]]; then

View File

@ -4,6 +4,8 @@
# number. Will return instead of exit when the shell is interactive.
# Put this in ${fpath} and load it with `autoload -U die`.
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
local errorcode=${?}
if [[ -v 1 && ${1} =~ '^[0-9]+$' ]]; then
errorcode=${1}

View File

@ -1,6 +1,8 @@
#!/usr/bin/env zsh
# Export variable to Emacs.
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
if [[ ARGC -eq 0 ]]; then
print -u 2 "Usage: ${0} <variable> …"
return 1

View File

@ -1,6 +1,8 @@
#!/usr/bin/env zsh
# Get backtrace from gdb
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
if [[ ${ARGC} -ne 2 ]]; then
print -u 2 "Usage: ${0} <executable> <core dump>"
return 1

View File

@ -2,6 +2,8 @@
# Makes all files in <directory> lower case. Works with Non-ASCII characters.
# Equivalent to `zmv "${dir}/(*)" '${dir}/${1:l}'`
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
if [[ ${ARGC} -ne 1 ]]; then
print -u 2 "Usage: ${0} <directory>"
return 1

View File

@ -1,6 +1,8 @@
#!/usr/bin/env zsh
# Put files on a webspace via sftp
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
if [[ ${ARGC} -eq 0 ]]; then
print -u 2 "Usage: ${0} <file> …"
return 1