commit 100b4796666dbe0f35f73daec19cb623b6d42bc9
parent 020da4058422c99e8a826c6f9019eb97bb9712d9
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Wed, 21 Aug 2019 10:28:23 +0200
Fix man9 on void, use tabs for indent
Diffstat:
M | .commands.sh | | | 207 | ++++++++++++++++++++++++++++++++++++++++--------------------------------------- |
1 file changed, 106 insertions(+), 101 deletions(-)
diff --git a/.commands.sh b/.commands.sh
@@ -18,43 +18,43 @@ alias ch='cd "$(dirs -lp | sort -u | fzy)"' # cd from history
# change to directory under pwd
c() {
- dir
- dir=$(find "${1:-.}" -type d | grep -v '/\.' | fzf)
- [ -d "$dir" ] && cd "$dir" || return
+ dir
+ dir=$(find "${1:-.}" -type d | grep -v '/\.' | fzf)
+ [ -d "$dir" ] && cd "$dir" || return
}
## ls
if [ "$(uname)" != 'Darwin' ]; then
- alias ls='ls --color=auto -F'
+ alias ls='ls --color=auto -F'
else
- alias ls='ls -G -F'
+ alias ls='ls -G -F'
fi
alias l='ls -alFh'
alias la='ls -A'
## Open files
o() {
- [ "$(uname)" = 'Darwin' ] && open="open" || open="xdg-open"
- if [ "$#" -gt 0 ] && [ -f "$1" ]; then
- setsid $open "$1" >/dev/null 2>&1
- else
- IFS= out=$(fzf --query="$1" --exit-0 \
- --expect=ctrl-o,ctrl-e,ctrl-y \
- --preview-window=hidden)
- key=$(echo "$out" | sed 1q)
- file=$(echo "$out" | sed 2q | tail -1)
- if [ -n "$file" ]; then
- if [ "$key" = ctrl-e ]; then
- ${EDITOR:-vim} "$file"
- elif [ "$key" = ctrl-y ]; then
- printf "%s" "$PWD/$file" | xclip
- elif [ "$key" = ctrl-o ]; then
- cd "$(dirname "$file")" || return
- else
- setsid $open "$file" >/dev/null 2>&1
- fi
- fi
- fi
+ [ "$(uname)" = 'Darwin' ] && open="open" || open="xdg-open"
+ if [ "$#" -gt 0 ] && [ -f "$1" ]; then
+ setsid $open "$1" >/dev/null 2>&1
+ else
+ IFS= out=$(fzf --query="$1" --exit-0 \
+ --expect=ctrl-o,ctrl-e,ctrl-y \
+ --preview-window=hidden)
+ key=$(echo "$out" | sed 1q)
+ file=$(echo "$out" | sed 2q | tail -1)
+ if [ -n "$file" ]; then
+ if [ "$key" = ctrl-e ]; then
+ ${EDITOR:-vim} "$file"
+ elif [ "$key" = ctrl-y ]; then
+ printf "%s" "$PWD/$file" | xclip
+ elif [ "$key" = ctrl-o ]; then
+ cd "$(dirname "$file")" || return
+ else
+ setsid $open "$file" >/dev/null 2>&1
+ fi
+ fi
+ fi
}
## dotfiles
@@ -95,125 +95,130 @@ alias gcagp='git commit --all --verbose --gpg-sign && git push'
# redefine git log alias
alias gl="git log --graph --oneline --decorate --all --color=always |
- fzf --ansi +s --preview='git show --color=always {2}' \
- --bind='pgdn:preview-page-down' \
- --bind='pgup:preview-page-up' \
- --bind='enter:execute:git show --color=always {2} | less -R' \
- --bind='ctrl-x:execute:git checkout {2} .'"
+ fzf --ansi +s --preview='git show --color=always {2}' \
+ --bind='pgdn:preview-page-down' \
+ --bind='pgup:preview-page-up' \
+ --bind='enter:execute:git show --color=always {2} | less -R' \
+ --bind='ctrl-x:execute:git checkout {2} .'"
## grep
alias grep='grep --color=auto'
## speech synthesis
if [ "$(uname)" != 'Darwin' ]; then
- say() { echo "$@" | festival --tts; }
- sayfile() { festival --tts "$@"; }
+ say() { echo "$@" | festival --tts; }
+ sayfile() { festival --tts "$@"; }
else
- sayfile() { say -f "$@"; }
+ sayfile() { say -f "$@"; }
fi
## w3m
alias w3m="w3m -B"
w3mtor() {
- url
- if [ $# -eq 0 ]; then
- url="https://check.torproject.org/"
- else
- url=$1
- fi
- torify w3m "$url"
+ if [ $# -eq 0 ]; then
+ url="https://check.torproject.org/"
+ else
+ url="$1"
+ fi
+ torify w3m "$url"
}
w3mddg() { torify surfraw ddg "$@"; }
news() {
- url
- if [ $# -eq 0 ]; then
- url="https://text.npr.org"
- elif [ "$1" = "npr" ]; then
- url="https://text.npr.org"
- elif [ "$1" = "cnn" ]; then
- url="https://lite.cnn.io/en"
- else
- url=$1
- fi
- torify w3m "$url"
+ if [ $# -eq 0 ]; then
+ url="https://text.npr.org"
+ elif [ "$1" = "npr" ]; then
+ url="https://text.npr.org"
+ elif [ "$1" = "cnn" ]; then
+ url="https://lite.cnn.io/en"
+ else
+ url="$1"
+ fi
+ torsocks w3m "$url"
}
## web services
weather() { curl "wttr.in/?m"; }
transfer() { # use transfer.sh to share files over the net
- if [ $# -eq 0 ]; then
- echo "No arguments specified. Usage: transfer.sh <file>"
- return 1
- fi
- tmpfile=$( mktemp -t transferXXX )
- if tty -s; then
- basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g')
- curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" \
- >> "$tmpfile"
- else
- curl --progress-bar --upload-file "-" "https://transfer.sh/$1" \
- >> "$tmpfile"
- fi
- cat "$tmpfile"
- rm -f "$tmpfile"
- echo ""
+ if [ $# -eq 0 ]; then
+ echo "No arguments specified. Usage: transfer.sh <file>"
+ return 1
+ fi
+ tmpfile=$( mktemp -t transferXXX )
+ if tty -s; then
+ basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g')
+ curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" \
+ >> "$tmpfile"
+ else
+ curl --progress-bar --upload-file "-" "https://transfer.sh/$1" \
+ >> "$tmpfile"
+ fi
+ cat "$tmpfile"
+ rm -f "$tmpfile"
+ echo ""
}
t_add() {
- transmission-remote --add --download-dir "$PWD" --encryption-required "$@"
+ transmission-remote --add --download-dir "$PWD" --encryption-required "$@"
}
t_list() {
- transmission-remote --list
+ transmission-remote --list
}
t_stop() {
- transmission-remote --torrent "$@" --stop
+ transmission-remote --torrent "$@" --stop
}
t_stop_idle() {
- for id in $(t-list | grep Done | grep Idle | awk '{ print $1 }' | tr '\n' ','); do
- t-stop "$id"
- done
+ for id in $(t-list | grep Done | grep Idle | awk '{ print $1 }' | tr '\n' ','); do
+ t-stop "$id"
+ done
}
t_remove() {
- transmission-remote --torrent "$@" --remove
+ transmission-remote --torrent "$@" --remove
}
t_remove_all() {
- transmission-remote -tall --remove
+ transmission-remote -tall --remove
}
m_all_sl() {
- for d in ~/.local/lib/dwm ~/.local/lib/st ~/.local/lib/surf \
- ~/.local/lib/tabbed ~/.local/lib/nnn; do
- echo
- echo "## Building $d"
- cd "$d" && make clean; make && sudo make install
- done
- cd - || return
+ for d in ~/.local/lib/dwm ~/.local/lib/st ~/.local/lib/surf \
+ ~/.local/lib/tabbed ~/.local/lib/nnn; do
+ echo
+ echo "## Building $d"
+ cd "$d" && make clean; make && sudo make install
+ done
+ cd - || return
}
gcagp_all_sl() {
- msg="Update color scheme"
- read -r "input?commit message [$msg]: "
- msg="${input:-$msg}"
- dotfiles add .Xresources
- dotfiles commit -m "$msg" --verbose --gpg-sign && git push;
- for d in ~/.local/lib/dwm ~/.local/lib/st ~/.local/lib/surf \
- ~/.local/lib/tabbed; do
- cd "$d" && \
- git branch && \
- git commit --all -m "$msg" --verbose --gpg-sign && git push;
- cd - || return
- done
+ msg="Update color scheme"
+ read -r "input?commit message [$msg]: "
+ msg="${input:-$msg}"
+ dotfiles add .Xresources
+ dotfiles commit -m "$msg" --verbose --gpg-sign && git push;
+ for d in ~/.local/lib/dwm ~/.local/lib/st ~/.local/lib/surf \
+ ~/.local/lib/tabbed; do
+ cd "$d" && \
+ git branch && \
+ git commit --all -m "$msg" --verbose --gpg-sign && git push;
+ cd - || return
+ done
}
man9() {
- plan9mans="/opt/plan9/share/man/man1"
- if [ $# -lt 1 ]; then
- 1="$(cd "$plan9mans" && find -- * -type f | sed 's/\.1$//' | fzy)"
- fi
- f="$plan9mans/${1}.1"
- [ -e "$f" ] && man "$f"
+ if [ -d /usr/lib/plan9 ]; then
+ plan9mans="/usr/lib/plan9/man/man1"
+ elif [ -d /opt/plan9 ]; then
+ plan9mans="/opt/plan9/share/man/man1"
+ else
+ (>&2 echo "no plan9 port installed")
+ return 1
+ fi
+ if [ $# -lt 1 ]; then
+ 1="$(cd "$plan9mans" && find -- * -type f | sed 's/\.1$//' | fzy)"
+ fi
+ f="$plan9mans/${1}.1"
+ [ -e "$f" ] && man "$f"
}
# shellcheck source=/dev/null