diff options
author | Karel Kočí <cynerd@email.cz> | 2018-01-26 15:02:07 +0100 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2018-01-26 15:26:36 +0100 |
commit | 47d3b6fc1966df43b37751165d6fa4229904c0fa (patch) | |
tree | cccb190aad69ed1afb93654922575a95e7745d03 | |
download | shellrc-47d3b6fc1966df43b37751165d6fa4229904c0fa.tar.gz shellrc-47d3b6fc1966df43b37751165d6fa4229904c0fa.tar.bz2 shellrc-47d3b6fc1966df43b37751165d6fa4229904c0fa.zip |
Initial commitv0.1
-rw-r--r-- | bash-completion/gitbmerge | 21 | ||||
-rw-r--r-- | bashrc.d/prompt | 16 | ||||
-rw-r--r-- | bashrc.d/shellrc | 5 | ||||
-rw-r--r-- | bashrc.d/title | 11 | ||||
-rw-r--r-- | shellrc.d/common | 84 | ||||
-rw-r--r-- | shellrc.d/desktop | 4 | ||||
-rw-r--r-- | shellrc.d/xorg | 34 | ||||
-rw-r--r-- | zsh-completion/_gitbmerge | 23 | ||||
-rw-r--r-- | zshrc | 5 | ||||
-rw-r--r-- | zshrc.d/bell | 37 | ||||
-rw-r--r-- | zshrc.d/common | 23 | ||||
-rw-r--r-- | zshrc.d/completion | 11 | ||||
-rw-r--r-- | zshrc.d/prompt | 17 | ||||
-rw-r--r-- | zshrc.d/shellrc | 5 | ||||
-rw-r--r-- | zshrc.d/title | 12 |
15 files changed, 308 insertions, 0 deletions
diff --git a/bash-completion/gitbmerge b/bash-completion/gitbmerge new file mode 100644 index 0000000..8706fc8 --- /dev/null +++ b/bash-completion/gitbmerge @@ -0,0 +1,21 @@ +_gitbmerge() { + local cur prev + _init_completion || return + [ $COMP_CWORD -gt 1 ] && return # Complete only single dependency + COMPREPLY=() + local GDIR="$(pwd)" + while [ ! -d "$GDIR/.git" ]; do + [ -z "$GDIR" ] && return + GDIR="${GDIR%/*}" + done + GDIR="$GDIR/.git" + [ -f "$GDIR" ] && GDIR="$(cat "$GDIR")" # This just points to some other directory + [ -d "$GDIR/refs/heads" ] || return # No completion if there is no local branch + local ops="" + for B in "$GDIR"/refs/heads/*; do + # TODO skip branch on HEAD + ops="$ops ${B#$GDIR/refs/heads/}" + done + COMPREPLY+=($(compgen -W "${ops}" -- ${cur})) +} +complete -F _gitbmerge gitbmerge diff --git a/bashrc.d/prompt b/bashrc.d/prompt new file mode 100644 index 0000000..dee3e53 --- /dev/null +++ b/bashrc.d/prompt @@ -0,0 +1,16 @@ +# vim: ft=sh + +PS1='$( +if [ `id -u` -eq "0" ]; then + echo -n "\[\e[1;31m\]\u@\h:\[\e[1;34m\]\W\[\e[1;31m\]\$\[\e[0m\] " +else + echo -n "\[\e[1;32m\]\u@\h:\[\e[1;34m\]\W\[\e[1;32m\]\$\[\e[0m\] " +fi)' + +PROMPT_COMMAND=' +EC=$? +if [[ $EC < 0 ]]; then + echo -e "\e[1;31m"EXIT: $EC"\e[0m" +elif [[ $EC > 0 ]]; then + echo -e "\e[1;33m"EXIT: $EC"\e[0m" +fi' diff --git a/bashrc.d/shellrc b/bashrc.d/shellrc new file mode 100644 index 0000000..9aef21c --- /dev/null +++ b/bashrc.d/shellrc @@ -0,0 +1,5 @@ +# vim: ft=sh + +for sh in /etc/shellrc.d/*; do + [ -r "$sh" ] && . "$sh" +done diff --git a/bashrc.d/title b/bashrc.d/title new file mode 100644 index 0000000..d6bb5e1 --- /dev/null +++ b/bashrc.d/title @@ -0,0 +1,11 @@ +# vim: ft=sh + +function settitle { + echo -ne "\033]0;`whoami`@`hostname`:`pwd`\007" +} + +case "$TERM" in + xterm*|*rxvt*|*st*) + trap 'settitle' DEBUG + ;; +esac diff --git a/shellrc.d/common b/shellrc.d/common new file mode 100644 index 0000000..ce744ea --- /dev/null +++ b/shellrc.d/common @@ -0,0 +1,84 @@ +# vim: ft=sh: + +alias ls='ls --color=auto' +eval $(dircolors -b) +alias ll='ls -lh' +alias df='df -h' +alias du='du -h' +alias grep='grep --color=auto' +alias git='LANG=en_GB git' +alias gdb='gdb -q' +alias cgdb='cgdb -q' +alias octave='octave-cli -q' +alias ssh='TERM="xterm-256color" ssh' +alias gst='git status' +alias v='vim' + +export LESS=-R +export LESS_TERMCAP_mb=$'\E[1;31m' +export LESS_TERMCAP_md=$'\E[1;36m' +export LESS_TERMCAP_me=$'\E[0m' +export LESS_TERMCAP_se=$'\E[0m' +export LESS_TERMCAP_so=$'\E[01;44;33m' +export LESS_TERMCAP_ue=$'\E[0m' +export LESS_TERMCAP_us=$'\E[1;32m' +[ -x /usr/bin/src-hilite-lesspipe.sh ] && export LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s" + +# Systemd aliases if we are running systemd +if pidof systemd >/dev/null 2>/dev/null; then + alias sctl='sudo systemctl' + alias usctl='systemctl --user' + alias jrn='journalctl' + alias ujrn='jrn --user' +fi + + +# Run process in background +tobg() { + "$@" >/dev/null 2>&1 & +} + +# Generate random password (optionally takes length of password as first argument) +genpasswd() { + local l=$1 + [ -n "$l" ] || l=16 + tr -dc A-Za-z0-9_ < /dev/urandom | head -c "$l" | xargs +} + +# Automatic branch merger (merge branch, push it to server and remove branch) +# Expects name of the branch as argument +gitbmerge() { + ( + set -e + local WT="$(git worktree list | sed -nE "/\[$1\]/{s/([^ ]+) .*/\1/p}")" + if [ -n "$WT" ]; then + rm -r "$WT" + git worktree prune + fi + git merge --ff-only "$1" && git push && git branch -d "$1" && git push origin :"$1" + ) +} + +# Create new branch from master +gitbnew() { + git branch "$1" master + local NW="$(git rev-parse --show-toplevel)-$1" + git worktree add "$NW" $1 + cd "$NW" + git submodule update --init --recursive +} + +# Run given command every second +dorepeat() { + while true; do + "$@" + sleep 1 + echo + done +} + +# Clear all ssh control masters +ssh-clear() { + rm -rf ~/.cache/ssh + mkdir -p ~/.cache/ssh +} diff --git a/shellrc.d/desktop b/shellrc.d/desktop new file mode 100644 index 0000000..e669b7d --- /dev/null +++ b/shellrc.d/desktop @@ -0,0 +1,4 @@ +# vim: ft=sh: +# This is handy only on desktop and is useless on server + +alias mutt='neomutt' diff --git a/shellrc.d/xorg b/shellrc.d/xorg new file mode 100644 index 0000000..2326b54 --- /dev/null +++ b/shellrc.d/xorg @@ -0,0 +1,34 @@ +# vim: ft=sh: +# These are utility functions loaded when we are running in Xserver + +[ -z "$DISPLAY" ] && return # Ignore if there is no display set + + +alias feh='feh --magick-timeout 10 -.' + +alias i='i3-msg' + + +# Clip stdin to clipboard +clip() { + # Note: printf as magic to remove trailing new lines + printf %s "$(cat)" | xclip -selection clipboard +} + +# Clip current HEAD hash to clipboard +# Optionally you can pass commit as argument +gitclip() { + [ -n "$1" ] && local CMT="$1" || local CMT=HEAD + git rev-parse "$CMT"| clip +} +# Clip current head message to clipboard +# Optionally you can pass commit as argument +gitmclip() { + [ -n "$1" ] && local CMT="$1" || local CMT=HEAD + git log --format=%B -n 1 "$CMT" | clip +} + +# Make screenshot +xshot() { + import -window "$(xdotool selectwindow)" ~/xshot_$(date +%F_%H%M%S_%N).png +} diff --git a/zsh-completion/_gitbmerge b/zsh-completion/_gitbmerge new file mode 100644 index 0000000..733dbfb --- /dev/null +++ b/zsh-completion/_gitbmerge @@ -0,0 +1,23 @@ +#compdef gitbmerge +#autoload + +_gitbmerge() { + (( CURRENT > 2)) && return # Complete only single dependency + local GDIR="$(pwd)" + while [ ! -d "$GDIR/.git" ]; do + [ -z "$GDIR" ] && return + GDIR="${GDIR%/*}" + done + GDIR="$GDIR/.git" + [ -f "$GDIR" ] && GDIR="$(cat "$GDIR")" # This just points to some other directory + [ -d "$GDIR/refs/heads" ] || return # No completion if there is no local branch + local branches=() + for B in "$GDIR"/refs/heads/*; do + # TODO skip branch on HEAD + branches+=("${B#$GDIR/refs/heads/}") + done + _describe -t branches 'gitbmerge' branches +} + +_gitbmerge +# vim: ft=zsh @@ -0,0 +1,5 @@ +[[ -o interactive ]] || return # skip on initialization if not interactive + +for sh in /etc/zsh/zshrc.d/*; do + [ -r "$sh" ] && . "$sh" +done diff --git a/zshrc.d/bell b/zshrc.d/bell new file mode 100644 index 0000000..5fbb5c4 --- /dev/null +++ b/zshrc.d/bell @@ -0,0 +1,37 @@ +# vim: ft=zsh +# Long running bell +# Inspired by: https://gist.github.com/jpouellet/5278239 + +zmodload zsh/datetime # load $EPOCHSECONDS builtin +autoload -Uz add-zsh-hook +lrbell_duration=15 +lrbell_timestamp=$EPOCHSECONDS +lrbell_window_id=0x0 + +lrbell_active_window_id() { + xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2 +} + +lrbell_begin() { + lrbell_timestamp=$EPOCHSECONDS + if [ -n "$DISPLAY" ]; then + lrbell_message="`pwd`: $1" + lrbell_window_id="$(lrbell_active_window_id)" + fi +} + +lrbell_end() { + if (( $EPOCHSECONDS - $lrbell_timestamp < $lrbell_duration )); then + return + fi + + print -n '\a' + if [ -n "$DISPLAY" ] && [ -n "$lrbell_window_id" ]; then # notify only if running in X + if [ "$(lrbell_active_window_id)" != "$lrbell_window_id" ]; then # And active window isn't current one + notify-send "Command finished" "$lrbell_message" + fi + fi +} + +add-zsh-hook preexec lrbell_begin +add-zsh-hook precmd lrbell_end diff --git a/zshrc.d/common b/zshrc.d/common new file mode 100644 index 0000000..9ba1466 --- /dev/null +++ b/zshrc.d/common @@ -0,0 +1,23 @@ +# vim: ft=zsh + +autoload -Uz colors && colors + +HISTFILE=~/.histfile +HISTSIZE=10000 +SAVEHIST=10000 +setopt appendhistory +setopt extendedglob +setopt hist_ignore_dups +setopt hist_expire_dups_first +setopt extended_history +setopt inc_append_history +setopt promptsubst +unsetopt nomatch +bindkey -e + +autoload -U select-word-style +select-word-style bash + +# Delete key workaround +bindkey "^[[3~" delete-char +bindkey "^[3;5~" delete-char diff --git a/zshrc.d/completion b/zshrc.d/completion new file mode 100644 index 0000000..595489c --- /dev/null +++ b/zshrc.d/completion @@ -0,0 +1,11 @@ +# vim: ft=zsh + +zstyle ':completion:*' completer _expand _complete _ignored _approximate +zstyle ':completion:*' insert-unambiguous true +zstyle ':completion:*' max-errors 3 +zstyle ':completion:*' use-cache on +zstyle ':completion:*' cache-path ~/.cache/zsh +zstyle -e ':completion:*:default' list-colors 'reply=("${PREFIX:+=(#bi)($PREFIX:t)(?)*==32=33}:${(s.:.)LS_COLORS}")' +zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} + +autoload -Uz compinit && compinit diff --git a/zshrc.d/prompt b/zshrc.d/prompt new file mode 100644 index 0000000..07437b1 --- /dev/null +++ b/zshrc.d/prompt @@ -0,0 +1,17 @@ +# vim: ft=zsh + +[ $UID -eq 0 ] && NCOLOR="red" || NCOLOR="green" +PROMPT="%(?..%{$fg_bold[yellow]%}EXIT: %? +)%{$fg_bold[$NCOLOR]%}%n@%m:%{$fg_bold[blue]%}%1~%{$fg_bold[$NCOLOR]%}%(!.#.$)%{$reset_color%} " +unset NCOLOR + +if [ -e ~/.local/git-prompt.sh ]; then + source ~/.local/git-prompt.sh + export GIT_PS1_SHOWDIRTYSTATE=y + export GIT_PS1_SHOWUNTRACKEDFILES=y + export GIT_PS1_SHOWUPSTREAM="auto" + export GIT_PS1_STATESEPARATOR="" + export GIT_PS1_SHOWUPSTREAM=y + export GIT_PS1_DESCRIBE_STYLE="branch" + RPROMPT='$(__git_ps1 "%s")' +fi diff --git a/zshrc.d/shellrc b/zshrc.d/shellrc new file mode 100644 index 0000000..b3162f7 --- /dev/null +++ b/zshrc.d/shellrc @@ -0,0 +1,5 @@ +# vim: ft=zsh + +for sh in /etc/shellrc.d/*; do + [ -r "$sh" ] && . "$sh" +done diff --git a/zshrc.d/title b/zshrc.d/title new file mode 100644 index 0000000..18b19d1 --- /dev/null +++ b/zshrc.d/title @@ -0,0 +1,12 @@ +# vim: ft=zsh + +case "$TERM" in + xterm*|*rxvt*|*st*) + precmd() { + print -Pn "\e]0;%n@%m:%~ %(1j,%j job%(2j|s|) ,)\a" + } + preexec() { + print -Pn "\e]0;%n@%m:%~ !$1\a" + } + ;; +esac |