dotfiles/.config/zsh/functions.zsh

42 lines
838 B
Bash

#!/bin/zsh
# Various functions, to be sourced.
# 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
function cat-highlight()
{
if [[ -t 1 ]]; then # We're in a terminal
CATOPEN="${LESSOPEN/| }"
CATOPEN="${CATOPEN/ %s}"
cat $@ | eval ${CATOPEN}
else
cat $@
fi
}