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

54 lines
1.2 KiB
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. 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
}