1
0
Fork 0
dotfiles/.config/zsh/functions.zsh

71 lines
1.6 KiB
Bash

#!/bin/zsh
# Various small functions
# Get backtrace from gdb.
function gdb_get_backtrace()
{
local exe=$1
local core=$2
gdb ${exe} \
--core ${core} \
--batch \
--quiet \
-ex "thread apply all bt full" \
-ex "quit"
}
# Export variable to Emacs.
function export-emacs
{
if [[ "$(emacsclient -e t)" != 't' ]]; then
return 1
fi
for name in "${@}"; do
value=$(eval echo \"\$${name}\")
emacsclient -e "(setenv \"${name}\" \"${value}\")" >/dev/null
done
}
# 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
local -a files
for arg in $@; do
# Filter out file names
if [[ "${arg:0:1}" != "-" ]]; then
files+="$arg"
else
args+="$arg"
fi
done
local catopen="${LESSOPEN/|/}"
eval "${catopen/\%s/${files}} | \cat ${args}"
else
\cat $@
fi
}
# Makes all files in DIR lower case. Works with Non-ASCII characters.
# Equivalent to `zmv "${dir}/(*)" '${dir}/${1:l}'`
function mksmol()
{
if [[ ${ARGC} -ne 1 ]]; then
echo "usage: ${0} DIR" >&2
return 1
fi
local dir="${1}"
for file in "${dir}"/*; do
basename="${file##*/}"
newfile="${dir}/${basename:l}"
[[ "${file}" != "${newfile}" ]] && mv "${file}" "${newfile}" || :
done
}