summaryrefslogtreecommitdiff
path: root/.bashrc
blob: 655e272fe298587f647851e09813348bc560e8a5 (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
# --- preferences

# load standard environment variables
. $HOME/.shenv

# '>' is a nice prompt char because it need not be followed by a
# space.  It is easy to distinguish the command from the prompt
PS1='$(exit_code=$?; test $exit_code -eq 0 || printf %s $exit_code " ")\u@\h:\w>'

# if this is an xterm set its title to user@host:dir
# (this doesn't stop the likes of ncmpcpp setting a title)
case "$TERM" in
    xterm*|rxvt*)
        PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h:\w\a\]$PS1"
        ;;
    *)
        ;;
esac

# enable better completion
if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi

# history settings
HISTCONTROL=ignorespace:ignoredups

# make less more friendly for non-text input files; see lesspipe(1)
if [ -x /usr/bin/lesspipe ]; then
    eval "$(lesspipe)"
fi

# --- aliases

alias ls="ls --color=auto --literal --classify"
alias grep="grep --colour=auto"

alias g="git"
alias ga="git annex"
alias mg="$EDITOR"
alias vi="$EDITOR"
alias e="$EDITOR"
alias mrs="mr -m status"
alias d="emacsclient -c -n -e '(dired \".\")'"
alias ta="tmux attach-session"
alias rax="screen -URaAx"

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 madison="ssh mirror.ftp-master.debian.org dak ls"
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 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)"

# --- more powerful aliases built with shell functions

# run a package build and the full suite of checks that I can do
# locally before an upload.  Generally I use this on an UNRELEASED
# package and then use `dgit push-source` for the actual upload
sbuild-preupload() {
    local dgit=""
    local sbuild=""
    for key in "$@"; do
        case $key in
            --gbp|--dpm|--quilt=*)
                dgit="$dgit $key"
                shift
                ;;
            *)
                sbuild="$sbuild $key"
                shift
                ;;
        esac
    done
    case $(pwd) in
        *src/DHG_packages/p*)
            sbuild $sbuild \
                   --no-run-lintian --run-piuparts --run-autopkgtest
            ;;
        *)
            eval dgit $dgit sbuild $sbuild \
                 --no-run-lintian --run-piuparts --run-autopkgtest
    esac
    lintian
}

# copy files into /home/spw/tmp for use in develacc container.  cp(1)
# does not respect ACLs, so we need to set a temporary umask before
# copying, and --no-preserve=mode to ensure that group-unreadable
# files become group-readable (i.e. have cp(1) follow the umask we
# just set).  Together with the setgid perms on /home/spw and
# subdirectories, this should ensure that spw is able to manipulate
# copied files and directories
copy-to-develacc () {
    (
        umask 002
        cp --no-preserve=mode -RL "$@" /home/spw/tmp
    )
}
# copy files into /root/tmp in develacc container.  Mainly used for
# .debs I want to install and test in that container
copy-to-develaccr () {
        sudo cp -RL "$@" /var/lib/container/develacc/root/tmp/
}

# tidy up if I deleted files from stowed repos without properly
# restowing
kill-broken-stowed-symlinks () {
    find "$HOME" -xtype l | while read -r link; do
        if readlink "$link" | grep --quiet "^[../]*/.STOW/"; then
            rm "$link"
        fi
    done
}

# 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
}