summaryrefslogtreecommitdiff
path: root/archive/.bash_defns
blob: 2ce5944428903366ebaa22f8a5621c95e84e48a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# This file was for core aliases & functions which we wanted available in
# shell commands run from Emacs.  However, nowadays I mostly use
# Eshell, so I moved these back to .shinit.  The following code was in
# init.el, and .bashrc *sourced* .bash_defns (BASH_ENV *not* set there):
#
# (when-let ((bash (executable-find "bash")))
#   (setq shell-file-name "bash")
#   (setenv "SHELL" bash)
#   (setenv "BASH_ENV" (expand-file-name "~/.bash_defns")))

shopt -s expand_aliases

# --- aliases

alias soffice-pdf="soffice --headless --convert-to pdf"
alias new-login-shell="exec su -l $USER" # get new UNIX group without relog
alias b="bts --mbox show"

# alias develacc='sudo machinectl shell spw@develacc \
#       $(sudo enter-develacc /bin/sh -c "getent passwd spw | cut -d: -f7")'
# alias develaccr='sudo machinectl shell root@develacc \
#       $(sudo enter-develacc /bin/sh -c "getent passwd root | cut -d: -f7")'

alias whitenoise="echo -en \"\033]0;whitenoise\a\";\
      cvlc --quiet --loop ~/annex/media/sounds/R*.ogg"

alias host-suite-build-deps='mk-build-deps -ir -s sudo -t \
      "apt-get --no-install-recommends"'
alias sid-build-deps='mk-build-deps -ir -s sudo -t \
      "apt-get -o Debug::pkgProblemResolver=yes -t sid --no-install-recommends"'
alias bts-policy="bts user debian-policy@packages.debian.org \
      , package debian-policy , "
alias dak-rdeps="ssh mirror.ftp-master.debian.org dak rm -Rn"
alias afsid="apt-file --filter-suites unstable"
alias dinstall="curl https://ftp-master.debian.org/dinstall.status;echo -n 'Right now:    ';date -u '+%a %b %d %T %Z %Y (%s)'"
# use with care, in order for this to actually provide a security advantage
alias update-debian-known-hosts="scp master.debian.org:/etc/ssh/ssh_known_hosts ~/src/dotfiles/.ssh/known_hosts_debian"
# from dgit-user(7), this pushes a non-native package through sbuild
# without an orig.tar for the version in the first changelog entry.
# Useful for sbuilding an unreleased version of a package I maintain
# upstream
alias sbuild-prerelease="sbuild --dpkg-source-opts='-Zgzip -z1 --format=1.0 -sn' --no-run-lintian"

# alias does not call `git develacc` because we want manual
# verification of what is to be pushed (i.e. `git diff
# master..develacc/develacc-iris` to check patch queue is sane)
alias push-develacc-dotfiles-branch="git push \
      -f origin develacc/develacc-$(hostname -s):develacc-$(hostname -s)"

alias spin-this-host-now='(cd /usr/local/propellor && sudo ./propellor)'

# --- more powerful aliases built with shell functions

secs () {
    for i in $(seq $1 -1 1); do
        echo $i
        sleep 1
    done
    echo 0
}

package-plan-unpack () {
    ~/src/dotfiles/scripts/debian/package-plan-unpack "$1"; cd "/tmp/$1"
}

# install package(s) and immediately mark as auto installed, so it
# will get cleaned up by the next autoclean.
# --no-install-recommends is needed as otherwise packages are manually
# installed beyond those specified on the command line
install-as-auto () {
    if [[ $EUID -ne 0 ]]; then
        sudo apt-get --no-install-recommends install "$@"
        sudo apt-mark auto "$@"
    else
        apt-get --no-install-recommends install "$@"
        apt-mark auto "$@"
    fi
}

# PDF word count
pdfwords () {
    pdftotext "$1" - | wc -w
}

# also see soffice-pdf alias above
soffice-pdf-all () {
    for f in *.doc *.docx; do
        soffice --headless --convert-to pdf "$f"
    done
}

# Debian archive processing logs
alias tail-dak="ssh ftp-master.debian.org tail -F \
      /srv/ftp-master.debian.org/log/current"
alias tail-queued="ssh ssh.upload.debian.org tail -F \
      /srv/upload.debian.org/queued/run/log"
grep-dak () {
    ssh ftp-master.debian.org grep "$@" /srv/ftp-master.debian.org/log/current
}
grep-queued () {
    ssh ssh.upload.debian.org grep "$@" /srv/upload.debian.org/queued/run/log
}

# sometimes a remote SSH session cannot get at my forwarded SSH agent
# because an unwanted instance of gpg-agent running on the remote host
# gets in the way.  this is a way to kill off that unwanted agent.  we
# also need to restart the multiplexed SSH connection to get agent
# forwarding working again.  I think this problem is mostly caused by
# the fact that I use gnupg as my SSH agent
kill-remote-gpg () {
    ssh "$1" 'rm -f $XDG_RUNTIME_DIR/gnupg/*'
    ssh -O exit "$1"
}

# build debs from a Linux kernel source tree *without* calling `make clean`.
#
# The -dbg deb takes some time to build.  To get rid of it when it's
# not needed: scripts/config --disable DEBUG_INFO
bindeb-pkg () {
    ver="$(make kernelversion)"
    date="$(date +%Y%m%d+%H%M)"
    arch="$(dpkg --print-architecture)"
    make -j$((2 * $(nproc))) bindeb-pkg \
      LOCALVERSION=-spw \
      KDEB_PKGVERSION=$ver-$date \
      "$@"
    echo "sudo apt-get install \
../linux-{image,headers}-$ver-spw_$ver-${date}_$arch.deb"
}

# --- host-specific aliases/functions

# not ftp-master.debian.org

# this is useful for processing removal requests
# (credits to Mark Wooding)
#
# alternative, by me, but involves spawning another process or two:
#
# command -v dak >/dev/null \
#     || alias dak="perl -MString::ShellQuote \
#         -we'system qw(ssh -t ftp-master.debian.org dak), shell_quote @ARGV'"
if ! command -v dak >/dev/null; then
    dak () {
        local i
        local c=
        for i; do               # implicit "in $@"
            c="$c '${i/\'/\'\\\'\'}'"
        done
        ssh -t ftp-master.debian.org dak "$c"
    }
fi