1
0
Fork 0

Zsh: Make functions also usable as shell scripts

This commit is contained in:
tastytea 2022-03-19 04:34:14 +01:00
parent 7cc2df5318
commit c00f5dce6e
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM
4 changed files with 57 additions and 69 deletions

View File

@ -1,9 +1,7 @@
# -*- mode: shell-script; -*-
#!/usr/bin/env zsh
# Highlight cat output with whatever less is using for highlighting. The command
# in $LESSOPEN needs to be able to work with multiple files.
function cat-highlight()
{
# Check if we are in a terminal and $LESSOPEN is not empty
if [[ -t 1 && -n "${LESSOPEN}" ]]; then
local -a args
@ -22,4 +20,3 @@ function cat-highlight()
else
\cat "${@}"
fi
}

View File

@ -1,8 +1,6 @@
# -*- mode: shell-script; -*-
#!/usr/bin/env zsh
# Export variable to Emacs.
function export-emacs
{
if [[ ARGC -eq 0 ]]; then
print -u 2 "Usage: ${0} <variable> …"
return 1
@ -15,4 +13,3 @@ function export-emacs
value=$(eval print \"\$${name}\")
emacsclient -e "(setenv \"${name}\" \"${value}\")" >/dev/null
done
}

View File

@ -1,8 +1,6 @@
# -*- mode: shell-script; -*-
#!/usr/bin/env zsh
# Get backtrace from gdb
function gdb_get_backtrace()
{
if [[ ${ARGC} -ne 2 ]]; then
print -u 2 "Usage: ${0} <executable> <core dump>"
return 1
@ -16,4 +14,3 @@ function gdb_get_backtrace()
--quiet \
-ex "thread apply all bt full" \
-ex "quit"
}

View File

@ -1,9 +1,7 @@
# -*- mode: shell-script; -*-
#!/usr/bin/env zsh
# Makes all files in <directory> lower case. Works with Non-ASCII characters.
# Equivalent to `zmv "${dir}/(*)" '${dir}/${1:l}'`
function mksmol()
{
if [[ ${ARGC} -ne 1 ]]; then
print -u 2 "Usage: ${0} <directory>" >&2
return 1
@ -15,4 +13,3 @@ function mksmol()
newfile="${dir}/${basename:l}"
[[ "${file}" != "${newfile}" ]] && mv "${file}" "${newfile}" || :
done
}