2022-03-18 14:34:27 +01:00
|
|
|
#!/bin/zsh
|
2022-03-18 23:11:27 +01:00
|
|
|
# Various small functions
|
2022-03-18 14:34:27 +01:00
|
|
|
|
|
|
|
# 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
|
|
|
|
}
|
2022-03-18 16:01:01 +01:00
|
|
|
|
2022-03-18 16:43:39 +01:00
|
|
|
# Highlight cat output with whatever less is using for highlighting. The command
|
2022-03-18 16:45:39 +01:00
|
|
|
# in $LESSOPEN needs to be able to work with multiple files.
|
2022-03-18 16:01:01 +01:00
|
|
|
function cat-highlight()
|
|
|
|
{
|
2022-03-18 16:12:44 +01:00
|
|
|
# Check if we are in a terminal and $LESSOPEN is not empty
|
|
|
|
if [[ -t 1 && -n "${LESSOPEN}" ]]; then
|
2022-03-18 16:43:39 +01:00
|
|
|
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
|
|
|
|
|
2022-03-18 17:33:21 +01:00
|
|
|
local catopen="${LESSOPEN/|/}"
|
2022-03-18 16:45:39 +01:00
|
|
|
eval "${catopen/\%s/${files}} | \cat ${args}"
|
2022-03-18 16:01:01 +01:00
|
|
|
else
|
2022-03-18 16:12:44 +01:00
|
|
|
\cat $@
|
2022-03-18 16:01:01 +01:00
|
|
|
fi
|
|
|
|
}
|
2022-03-18 23:11:27 +01:00
|
|
|
|
|
|
|
# Makes all files in DIR lower case. Works with Non-ASCII characters.
|
|
|
|
function mksmol()
|
|
|
|
{
|
|
|
|
if [[ ${ARGC} -ne 1 ]]; then
|
|
|
|
echo "usage: ${0} DIR" >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
local dir="${1}"
|
|
|
|
for file in "${dir}"/*; do
|
|
|
|
newfile="${file:l}"
|
|
|
|
[[ "${file}" != "${newfile}" ]] && mv "${file}" "${newfile}" || :
|
|
|
|
done
|
|
|
|
}
|