commit dd9f36c1540744c2e82bdbe68dbeae512159045b
parent 319e1bb11ffeb28bc90a94fb0ee2bf653fd077b3
Author: Oscar Benedito <oscar@oscarbenedito.com>
Date: Mon, 10 Jan 2022 20:16:05 +0100
Generalize .zshrc for other computers
- Prompt show $ or # depending on priviledges
- Imports now support other distros
- Allow host-specific configuration
- Moved some aliases to gray host specific file
- Move git-head-abbrev to zshrc
Diffstat:
7 files changed, 105 insertions(+), 92 deletions(-)
diff --git a/.config/zsh/aliases b/.config/zsh/aliases
@@ -21,6 +21,12 @@ alias vim="nvim"
alias vimdiff="nvim -d"
alias g="git"
alias t="tmux new -As0"
+alias c="git --git-dir=$HOME/.local/share/dotfiles --work-tree=$HOME"
+alias gv="nvim -c Git -c only"
+alias cv="(cd $HOME; GIT_DIR=$HOME/.local/share/dotfiles GIT_WORK_TREE=$HOME nvim -c Git -c only)"
+alias ca="cal -m -3"
+
+# I should probably change to "4." instead of "....."
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
@@ -33,41 +39,22 @@ alias ..........="cd ../../../../../../../../.."
alias ...........="cd ../../../../../../../../../.."
alias ............="cd ../../../../../../../../../../.."
alias .............="cd ../../../../../../../../../../../.."
-alias vw="cd $HOME/Documents/wiki && vim index.md"
-alias c="git --git-dir=$HOME/.local/share/dotfiles --work-tree=$HOME"
-alias gv="nvim -c Git -c only"
-alias cv="(cd $HOME; GIT_DIR=$HOME/.local/share/dotfiles GIT_WORK_TREE=$HOME nvim -c Git -c only)"
-alias autoremove="sudo pacman -Qtdq | sudo pacman -Rns -; yes | sudo pacman -Scc"
-alias ca="cal -m -3"
-alias volume="pasystray"
# frequent files and directories
alias cfa="$EDITOR $XDG_CONFIG_HOME/zsh/aliases"
alias cfe="$EDITOR $XDG_CONFIG_HOME/zsh/zshenv"
alias cfg="$EDITOR $XDG_CONFIG_HOME/git/config"
-alias cfp="$EDITOR $HOME/.profile"
alias cft="$EDITOR $XDG_CONFIG_HOME/tmux/tmux.conf"
alias cfv="$EDITOR $XDG_CONFIG_HOME/nvim/init.vim"
alias cfx="$EDITOR $XDG_CONFIG_HOME/Xresources"
alias cfz="$EDITOR $XDG_CONFIG_HOME/zsh/zshrc"
+alias cfh="$EDITOR $XDG_CONFIG_HOME/zsh/host-$(hostname -s)"
+
alias db="cd $HOME/.local/bin && ls"
-alias dbanc="cd /run/media/oscar/banc && ls"
alias dc="cd $HOME/Documents && ls"
-alias dg="cd $HOME/Git && ls"
alias ds="cd $HOME/.local/src && ls"
-alias dvw="cd $HOME/Documents/wiki && ls"
alias dw="cd $HOME/Downloads && ls"
-# update system
-up() {
- if ps aux | grep -q '[c]heckupdates'; then
- echo "checkupdates in progress, exiting..."
- else
- yay -Syu && yes | sudo pacman -Scc
- pkill -RTMIN+4 dwmblocks
- fi
-}
-
# dotfiles' repository metafiles
c-clean() {
rm -f "$HOME/README.md" "$HOME/COPYING"
@@ -78,45 +65,3 @@ c-populate() {
c update-index --no-skip-worktree "$HOME/README.md" "$HOME/COPYING"
c checkout "$HOME/README.md" "$HOME/COPYING"
}
-
-# unite pdf after double side scanning
-unite-pdf() {
- if [ -z "$1" ] || [ -z "$2" ]; then
- echo "Usage: unite-pdf odd even [output]"
- else
- [ -z "$3" ] && { 3="$(mktemp)" ; echo "$3" ; }
- pdftk "A=$1" "B=$2" shuffle A Bend-1 output "$3"
- fi
-}
-
-restart-wifi-daemon() {
- while true; do
- curl -Is http://oscarbenedito.com > /dev/null || \
- { printf "Restarting wifi..."; restart-wifi; printf " done at "; date +"%a %d %b, %H:%M"; printf "\n"; }
- sleep 30
- done
-}
-
-restart-wifi() {
- printf "Restarting wifi...";
- nmcli radio wifi off;
- sleep 1;
- nmcli radio wifi on;
- printf " done: ";
- date +"%a %d %b, %H:%M";
-}
-
-mount-banc() {
- sudo mkdir -p /run/media/oscar/banc || return
- sudo chown oscar:oscar /run/media/oscar/banc
- sshfs maroon:/media/banc /run/media/oscar/banc
- echo "ls /run/media/oscar"
- ls /run/media/oscar
-}
-
-umount-banc() {
- sudo umount /run/media/oscar/banc
- sudo rmdir /run/media/oscar/banc
- echo "ls /run/media/oscar"
- ls /run/media/oscar
-}
diff --git a/.config/zsh/host-gray b/.config/zsh/host-gray
@@ -0,0 +1,52 @@
+# vim: filetype=zsh
+
+alias dbanc="cd /run/media/oscar/banc && ls"
+alias dg="cd $HOME/Git && ls"
+
+alias vw="cd $HOME/Documents/wiki && vim index.md"
+alias dvw="cd $HOME/Documents/wiki && ls"
+
+alias autoremove="sudo pacman -Qtdq | sudo pacman -Rns -; yes | sudo pacman -Scc"
+alias volume="pasystray"
+
+# update system
+up() {
+ if ps aux | grep -q '[c]heckupdates'; then
+ echo "checkupdates in progress, exiting..."
+ else
+ yay -Syu && yes | sudo pacman -Scc
+ pkill -RTMIN+4 dwmblocks
+ fi
+}
+
+restart-wifi-daemon() {
+ while true; do
+ curl -Is http://oscarbenedito.com > /dev/null || \
+ { printf "Restarting wifi..."; restart-wifi; printf " done at "; date +"%a %d %b, %H:%M"; printf "\n"; }
+ sleep 30
+ done
+}
+
+restart-wifi() {
+ printf "Restarting wifi...";
+ nmcli radio wifi off;
+ sleep 1;
+ nmcli radio wifi on;
+ printf " done: ";
+ date +"%a %d %b, %H:%M";
+}
+
+mount-banc() {
+ sudo mkdir -p /run/media/oscar/banc || return
+ sudo chown oscar:oscar /run/media/oscar/banc
+ sshfs maroon:/media/banc /run/media/oscar/banc
+ echo "ls /run/media/oscar"
+ ls /run/media/oscar
+}
+
+umount-banc() {
+ sudo umount /run/media/oscar/banc
+ sudo rmdir /run/media/oscar/banc
+ echo "ls /run/media/oscar"
+ ls /run/media/oscar
+}
diff --git a/.config/zsh/zshenv b/.config/zsh/zshenv
@@ -1,8 +1,7 @@
# vim: filetype=zsh
# Local bin to path
-[ -d "$HOME/.local/bin" ] && \
- export PATH="$PATH:$(du "$HOME/.local/bin/" | cut -f2 | sed 's/\/$//g' | paste -sd ':')"
+[ -d "$HOME/.local/bin" ] && export PATH="$HOME/.local/bin:$PATH"
# XDG dirs
export XDG_DATA_HOME="$HOME/.local/share"
diff --git a/.config/zsh/zshrc b/.config/zsh/zshrc
@@ -1,10 +1,21 @@
# vim: filetype=zsh
-# Load colors and set up prompt
+
+# load colors and set up prompt
autoload -U colors && colors
setopt PROMPT_SUBST
-PS1='%B%{$fg[magenta]%}%n%{$fg[blue]%}@%{$fg[green]%}%m %{$fg[yellow]%}%~%b%{$fg[cyan]%}$(git-head-abbrev)%{$fg[red]%}$%{$reset_color%} '
-# Set up history and history file
+# prompt
+git-head-abbrev() {
+ c="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)"
+ if [ "$c" = "HEAD" ]; then
+ c="$(git describe --tags 2>/dev/null)"
+ [ -z "$c" ] && c="$(git rev-parse --short HEAD 2>/dev/null)"
+ fi
+ [ -n "$c" ] && printf " ($c)"
+}
+PS1='%B%{$fg[magenta]%}%n%{$fg[blue]%}@%{$fg[green]%}%m %{$fg[yellow]%}%~%b%{$fg[cyan]%}$(git-head-abbrev)%{$fg[red]%}%(!.#.$)%{$reset_color%} '
+
+# set up history and history file
HISTSIZE=100000
SAVEHIST=100000
HISTFILE=~/.cache/zsh/history
@@ -13,35 +24,41 @@ setopt HIST_IGNORE_DUPS
setopt HIST_FIND_NO_DUPS
setopt EXTENDED_HISTORY
-# Set up navigation menu when pressing tab multiple times
+# set up navigation menu when pressing tab multiple times
autoload -U compinit
zstyle ':completion:*' menu select
zmodload zsh/complist
compinit -d ~/.cache/zsh/zcompdump
#_comp_options+=(globdots)
-# Auto complete case insensitive
+# auto complete case insensitive
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
-# Set up vi style keys
+# set up vi style keys
bindkey -v
export KEYTIMEOUT=1
-# Also set vi keys to navigate the menus when double pressing tab
+# also set vi keys to navigate the menus when double pressing tab
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'l' vi-forward-char
bindkey -M menuselect 'j' vi-down-line-or-history
-# Process the alias file
[ -f "$XDG_CONFIG_HOME/zsh/aliases" ] && source "$XDG_CONFIG_HOME/zsh/aliases"
+[ -f "$XDG_CONFIG_HOME/zsh/host-$(hostname -s)" ] && source "$XDG_CONFIG_HOME/zsh/host-$(hostname -s)"
-# Process fzf key bindings
-# In other distributions, this file might be found at /usr/share/fzf/shell/key-bindings.zsh
-[ -f "/usr/share/fzf/key-bindings.zsh" ] && \
+# source fzf key bindings
+if [ -f "/usr/share/fzf/key-bindings.zsh" ]; then # arch
source "/usr/share/fzf/key-bindings.zsh" 2> /dev/null
+elif [ -f "/usr/share/doc/fzf/examples/key-bindings.zsh" ]; then # debian
+ source "/usr/share/doc/fzf/examples/key-bindings.zsh" 2> /dev/null
+elif [ -f "/usr/share/fzf/shell/key-bindings.zsh" ]; then # fedora
+ source "/usr/share/fzf/shell/key-bindings.zsh" 2> /dev/null
+fi
-# Include the highlighting plug-in
-# In other distributions, this file might be found at /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
-[ -f "/usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" ] && \
+# highlighting plug-in
+if [ -f "/usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" ]; then # arch and debian
source "/usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" 2> /dev/null
+elif [ -f "/usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" ]; then # fedora
+ source "/usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" 2> /dev/null
+fi
diff --git a/.local/bin/git-head-abbrev b/.local/bin/git-head-abbrev
@@ -1,8 +0,0 @@
-#!/bin/sh
-
-c="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)"
-if [ "$c" = "HEAD" ]; then
- c="$(git describe --tags 2>/dev/null)"
- [ -z "$c" ] && c="$(git rev-parse --short HEAD 2>/dev/null)"
-fi
-[ -n "$c" ] && printf " ($c)"
diff --git a/.local/bin/unite-pdf b/.local/bin/unite-pdf
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+# unite pdf after double side scanning
+if [ -z "$1" ] || [ -z "$2" ]; then
+ echo "Usage: unite-pdf odd even [output]"
+else
+ [ -z "$3" ] && { 3="$(mktemp)" ; echo "$3" ; }
+ pdftk "A=$1" "B=$2" shuffle A Bend-1 output "$3"
+fi
diff --git a/README.md b/README.md
@@ -68,7 +68,7 @@ Some of the programs you will need on a new installation are the following
```
# basic
-xf86-video-intel zsh zsh-syntax-highlighting fzf neovim wget man cronie htop sshfs dash pacman-contrib xclip
+xf86-video-intel zsh zsh-syntax-highlighting fzf neovim wget man cronie htop sshfs dash pacman-contrib xclip inetutils
# xorg
xorg-server xorg-xinit
# utils
@@ -115,15 +115,14 @@ If you just want to use a subset of the files without wanting to create a new
branch (for example in case you want to use them on a server), you can use `git
update-index --skip-worktree file1 file2` to stop tracking files and then delete
them. For example, to only use the files under `.zshenv`, `.config/zsh`,
-`.config/git`, `.config/nvim`, `.config/tmux` and `.local/bin/git-head-abbrev`,
-you could run the following:
+`.config/git`, `.config/nvim` and `.config/tmux`, you could run the following:
```
git --git-dir=/root/.local/share/dotfiles --work-tree=/root ls-files | \
- sed '/^\.config\/\(zsh\|git\|nvim\|tmux\)\|^\.zshenv\|^\.local\/bin\/git-head-abbrev/d' | \
+ sed '/^\.config\/\(zsh\|git\|nvim\|tmux\)\|^\.zshenv/d' | \
xargs git --git-dir=/root/.local/share/dotfiles --work-tree=/root update-index --skip-worktree
git --git-dir=/root/.local/share/dotfiles --work-tree=/root ls-files | \
- sed '/^\.config\/\(zsh\|git\|nvim\|tmux\)\|^\.zshenv\|^\.local\/bin\/git-head-abbrev/d' | \
+ sed '/^\.config\/\(zsh\|git\|nvim\|tmux\)\|^\.zshenv/d' | \
xargs rm -f
```