Zsh: Put functions in directory and autoload them
This commit is contained in:
parent
512682aa01
commit
7cc2df5318
@ -131,7 +131,8 @@ case $(hostname) in
|
||||
;;
|
||||
esac
|
||||
|
||||
[[ -f ${ZDOTDIR}/zsecrets ]] && source ${ZDOTDIR}/zsecrets
|
||||
[[ -f "${ZDOTDIR}"/zsecrets ]] && source "${ZDOTDIR}"/zsecrets
|
||||
[[ -d "${ZDOTDIR}"/functions ]] && fpath+="${ZDOTDIR}"/functions
|
||||
|
||||
############################# Daemons ##########################################
|
||||
|
||||
|
@ -181,9 +181,9 @@ esac
|
||||
precmd_functions=(${(u)precmd_functions})
|
||||
preexec_functions=(${(u)preexec_functions})
|
||||
|
||||
[[ -f ${ZDOTDIR}/zkeys ]] && source ${ZDOTDIR}/zkeys
|
||||
[[ -f ${ZDOTDIR}/zaliases ]] && source ${ZDOTDIR}/zaliases
|
||||
[[ -f ${ZDOTDIR}/functions.zsh ]] && source ${ZDOTDIR}/functions.zsh
|
||||
[[ -f "${ZDOTDIR}"/zkeys ]] && source "${ZDOTDIR}"/zkeys
|
||||
[[ -f "${ZDOTDIR}"/zaliases ]] && source "${ZDOTDIR}"/zaliases
|
||||
[[ -d "${ZDOTDIR}"/functions ]] && autoload -Uz "${ZDOTDIR}"/functions/*
|
||||
|
||||
local DEFAULT_USER="${DEFAULT_USER:-tastytea}"
|
||||
[[ -f ${ZDOTDIR}/tastytea.zsh-theme ]] && source ${ZDOTDIR}/tastytea.zsh-theme
|
||||
|
@ -1,70 +0,0 @@
|
||||
#!/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
|
||||
}
|
25
.config/zsh/functions/cat-highlight
Normal file
25
.config/zsh/functions/cat-highlight
Normal file
@ -0,0 +1,25 @@
|
||||
# -*- mode: shell-script; -*-
|
||||
|
||||
# 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[1]}" != "-" ]]; then
|
||||
files+="${arg}"
|
||||
else
|
||||
args+="${arg}"
|
||||
fi
|
||||
done
|
||||
|
||||
local catopen="${LESSOPEN/|/}"
|
||||
eval "${catopen/\%s/${files}} | \cat ${args}"
|
||||
else
|
||||
\cat "${@}"
|
||||
fi
|
||||
}
|
18
.config/zsh/functions/export-emacs
Normal file
18
.config/zsh/functions/export-emacs
Normal file
@ -0,0 +1,18 @@
|
||||
# -*- mode: shell-script; -*-
|
||||
|
||||
# Export variable to Emacs.
|
||||
function export-emacs
|
||||
{
|
||||
if [[ ARGC -eq 0 ]]; then
|
||||
print -u 2 "Usage: ${0} <variable> …"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Fail if we can't communicate with the daemon
|
||||
[[ "$(emacsclient -e t)" == 't' ]] || return 1
|
||||
|
||||
for name in "${@}"; do
|
||||
value=$(eval print \"\$${name}\")
|
||||
emacsclient -e "(setenv \"${name}\" \"${value}\")" >/dev/null
|
||||
done
|
||||
}
|
19
.config/zsh/functions/gdb_get_backtrace
Normal file
19
.config/zsh/functions/gdb_get_backtrace
Normal file
@ -0,0 +1,19 @@
|
||||
# -*- mode: shell-script; -*-
|
||||
|
||||
# Get backtrace from gdb
|
||||
function gdb_get_backtrace()
|
||||
{
|
||||
if [[ ${ARGC} -ne 2 ]]; then
|
||||
print -u 2 "Usage: ${0} <executable> <core dump>"
|
||||
return 1
|
||||
fi
|
||||
local exe="${1}"
|
||||
local core="${2}"
|
||||
|
||||
gdb "${exe}" \
|
||||
--core "${core}" \
|
||||
--batch \
|
||||
--quiet \
|
||||
-ex "thread apply all bt full" \
|
||||
-ex "quit"
|
||||
}
|
18
.config/zsh/functions/mksmol
Normal file
18
.config/zsh/functions/mksmol
Normal file
@ -0,0 +1,18 @@
|
||||
# -*- mode: shell-script; -*-
|
||||
|
||||
# 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
|
||||
fi
|
||||
local dir="${1}"
|
||||
|
||||
for file in "${dir}"/*; do
|
||||
basename="${file##*/}"
|
||||
newfile="${dir}/${basename:l}"
|
||||
[[ "${file}" != "${newfile}" ]] && mv "${file}" "${newfile}" || :
|
||||
done
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user