Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
259 lines (218 sloc) 4.64 KB
#!/bin/bash
abuild() {
local repo=${1:-extra}
sudo sh -c "'$repo-x86_64-build' && '$repo-i686-build'"
}
cget() {
curl -fJOL --compressed "$@"
}
confpac() {
[[ -f autogen.sh ]] || return 1
./autogen.sh
./configure \
--prefix=/usr \
--sysconfdir=/etc \
--localstatedir=/var \
--enable-git-version \
--enable-warningflags \
--enable-debug \
"$@"
}
pushd() {
builtin pushd "${@:-$HOME}"
}
./configure() {
if [[ -x /bin/dash ]]; then
CONFIG_SHELL=/bin/dash /bin/dash ./configure CONFIG_SHELL=/bin/dash "$@"
else
command ./configure "$@"
fi
}
debugflags() {
local -a flags cppflags ldflags
cflags=(-pedantic -Wall -Wextra -Wclobbered -Wempty-body -Wfloat-equal
-Wignored-qualifiers -Wmissing-declarations -Wmissing-parameter-type
-Wsign-compare -Wmissing-prototypes -Wold-style-declaration -gdwarf-4
-fstack-protector-all -Wtype-limits -Woverride-init -Wunused
-Wstrict-prototypes -Wuninitialized -fvar-tracking-assignments)
#cppflags=(-D_FORTIFY_SOURCE=2)
# lulz
for flagarr in {c,cpp,ld}flags; do
eval "${flagarr^^}=\${${flagarr}[*]}"
done
export {LD,C{,PP}}FLAGS
}
deps() {
local bin dir
if [[ -f "$1" ]]; then
bin=$1
elif bin=$(type -P "$1"); then
:
else
# maybe its a lib?
[[ -f /usr/lib/$1 ]] && bin=/usr/lib/$1
fi
if [[ $bin && $1 != "$bin" ]]; then
printf '%s => %s\n\n' "$1" "$bin"
fi
if [[ -z $bin ]]; then
echo "error: binary not found: $1"
return 1
fi
objdump -p "$bin" | awk '/NEEDED/ { print $2 }'
}
down() {
local OPTIND=0 flag= match= pred=
local -i i=0 first=0
local -a matches
_goto() {
if [[ -d $1 ]]; then
cd "$1"
else
cd "${1%/*}"
fi
}
while getopts 'bcdflps1' flag; do
case $flag in
b|c|d|f|l|p|s) pred="-type ${1#-}" ;;
1) first=1 ;;
*) return 1 ;;
esac
done
shift $(( OPTIND - 1 ))
# sort by depth
while IFS=$'\t' read -r _ match; do
matches[++i]=$match
done< <(find . $pred -name "$1" | awk -F'/' '{ printf "%s\t%s\n",NF,$0 }' | sort -n)
if (( ! ${#matches[*]} )); then
echo "no matches"
return 1
fi
if (( i == 1 || first )); then
_goto "${matches[1]}"
else
if (( $# == 1 )); then
i=0
for match in "${matches[@]}"; do
(( ++i ))
printf '%d) %s%s\n' "$i" "${matches[i]}" "$([[ -d ${matches[i]} ]] && printf '/')"
done
else
if (( $2 > i )); then
return 1
fi
_goto "${matches[$2]}"
fi
fi
}
hex2dec() {
printf "%d\n" 0x$1
}
hex2ip() {
printf '%d.%d.%d.%d\n' \
$(( 0x${1:6:2} )) \
$(( 0x${1:4:2} )) \
$(( 0x${1:2:2} )) \
$(( 0x${1:0:2} ))
}
ip2hex() {
local octets
IFS=. read -a octets <<<"$1"
printf '%02x' "${octets[@]}"
echo
}
kopt() {
[[ $1 ]] || return 1
zgrep "${1^^}" /proc/config.gz
}
ll() {
case $1 in
*.tar.gz|*.tgz)
bsdtar tvf "$1" | less
;;
*.tar.bz2|*.tbz)
bsdtar tvf "$1" | less
;;
*.tar.xz|*.txz)
bsdtar tvf "$1" | less
;;
*.tar)
bsdtar tvf "$1" | less
;;
*)
ls -l "$@"
esac
}
mkcd() {
[[ $1 ]] || return 0
[[ -d $1 ]] || mkdir -vp "$1"
[[ -d $1 ]] && builtin cd "$1"
}
signall() {
for _; do gpg --detach-sign "$_"; done
}
svnrm() {
svn up --set-depth exclude "$@" && rm -rf "$@"
}
t() {
tmux -L main "${@:-attach}"
}
tmp() {
mkcd ~/tmp
}
traffic() {
ss -t '( not dst localhost )' | awk '
NR > 1 {
sub(/:[^:]+$/, "", $NF)
a[$NF]++
}
END {
for (h in a)
printf "%s\t%d\n", h, a[h]
}'
}
up() {
local cdinto=0 x= traverse= curpath=
[[ $1 ]] || { cd ..; return; } # default to 1 level
[[ $1 = -d ]] && { cdinto=1; shift; }
for x; do
if [[ $x == +([[:digit:]]) ]]; then
(( x == 0 )) && return # noop
# build a path to avoid munging OLDPWD
while (( x-- )); do
traverse+=../
done
cd "$traverse"
else
curpath=$PWD
while [[ $curpath && ! -e $curpath/$x ]]; do
curpath=${curpath%/*}
done
if [[ $curpath ]]; then
if [[ $curpath != "$PWD" ]]; then
if (( cdinto )); then
cd "$curpath/$x"
else
cd "$curpath"
fi
fi
else
printf "error: failed to locate \`%s' in a parent directory\n" "$x"
return 1
fi
fi
done
}
urlencode() {
local i= char= url=$*
declare -i len=${#url}
for (( i = 0; i < len; i++ )); do
char=${url:i:1}
case "$char" in
[a-zA-Z0-9.~_-]) printf "$char" ;;
' ') printf + ;;
*) printf '%%%X' "'$char" ;;
esac
done
}
# vim: syn=sh ft=sh et
Something went wrong with that request. Please try again.