diff --git a/.zshrc b/.zshrc index 5e7b5df..cda7796 100644 --- a/.zshrc +++ b/.zshrc @@ -1,244 +1,9 @@ -# ~/.zshrc file for zsh interactive shells. -# see /usr/share/doc/zsh/examples/zshrc for examples - - - - - - - - - - -# >unironically using kali linux' zsh configuration as a template - - - - - - - - - - - - - -######################################## -# ALIASES # -######################################## - -alias ll='ls -l' -alias la='ls -A' -alias l='ls -CF' - -alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME' # dotfiles repo management - -alias pdf="zathura" -alias scrot="scrot -izs" -alias pacman="sudo pacman" -alias ghc="ghc --make -dynamic" -alias vim="nvim" -alias vi="nvim" -alias history="history 0" # force zsh to show the complete history - -# lazy -- compiles and runs c/c++ (debug mode) -lazy() { - cc $1 -o "${1:0:-2}.out" -lm -g3 && gdb -q -ex run ./${1:0:-2}.out -} - -# create directory and set it as cwd -take() { - if [ -z "$1" ] - then - read 1 - fi - - mkdir -p $1 - cd $1 -} - -# compile markdown to html and view in browser -m() { - if [[ -z "$2" ]]; then - 2="$HOME/air.css" - fi - - if [[ -z $1 ]]; then - 1="README.md" - fi - - pandoc $1 -f gfm --css=$2 --self-contained --metadata title=$1 | { qutebrowser "data:text/html;base64,$(base64 -w 0)" &} -} - -# same as above, but in lynx (terminal based web browser) -m2(){ - if [[ -z $1 ]]; then - 1="README.md" - fi - pandoc $1 | lynx -stdin -} - - -######################################## -# OPTIONS # -######################################## - -#setopt autocd # change directory just by typing its name -#setopt correct # auto correct mistakes -setopt interactivecomments # allow comments in interactive mode -setopt magicequalsubst # enable filename expansion for arguments of the form ‘anything=expression’ -setopt nonomatch # hide error message if there is no match for the pattern -setopt notify # report the status of background jobs immediately -setopt numericglobsort # sort filenames numerically when it makes sense -setopt promptsubst # enable command substitution in prompt -color_prompt=yes # enable colors -WORDCHARS=${WORDCHARS//\/} # Don't consider certain characters part of the word -PROMPT_EOL_MARK="" # hide EOL sign ('%') - -# enable completion features -autoload -Uz compinit -compinit -d ~/.cache/zcompdump -zstyle ':completion:*:*:*:*:*' menu select -zstyle ':completion:*' auto-description 'specify: %d' -zstyle ':completion:*' completer _expand _complete -zstyle ':completion:*' format 'Completing %d' -zstyle ':completion:*' group-name '' -zstyle ':completion:*' list-colors '' -zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s -zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' -zstyle ':completion:*' rehash true -zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s -zstyle ':completion:*' use-compctl false -zstyle ':completion:*' verbose true -zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd' - -# History configurations -HISTFILE=~/.zsh_history -HISTSIZE=1000 -SAVEHIST=2000 -setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE -setopt hist_ignore_dups # ignore duplicated commands history list -setopt hist_ignore_space # ignore commands that start with space -setopt hist_verify # show command with history expansion to user before running it -setopt share_history # share command history data - - -# configure `time` format -TIMEFMT=$'\nreal\t%E\nuser\t%U\nsys\t%S\ncpu\t%P' - -# make less more friendly for non-text input files, see lesspipe(1) -#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" - -# set variable identifying the chroot you work in (used in the prompt below) -if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then - debian_chroot=$(cat /etc/debian_chroot) +if [[ ! -v ZSH_CUSTOM ]]; then + $ZSH_CUSTOM=$HOME fi -# set a fancy prompt (non-color, unless we know we "want" color) -case "$TERM" in - xterm-color|*-256color) color_prompt=yes;; -esac +source $ZSH_CUSTOM/aliases.zsh +source $ZSH_CUSTOM/options.zsh +source $ZSH_CUSTOM/prompt.zsh - -configure_prompt() { - PROMPT=" 🐢 %F{240}%~ - $%f " - RPROMPT="%T - %?" -} - -if [ "$color_prompt" = yes ]; then - # override default virtualenv indicator in prompt - VIRTUAL_ENV_DISABLE_PROMPT=1 - - configure_prompt - - # enable syntax-highlighting - if [ -f /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ] && [ "$color_prompt" = yes ]; then - . /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh - ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern) - ZSH_HIGHLIGHT_STYLES[default]=none - ZSH_HIGHLIGHT_STYLES[unknown-token]=fg=red,bold - ZSH_HIGHLIGHT_STYLES[reserved-word]=fg=cyan,bold - ZSH_HIGHLIGHT_STYLES[suffix-alias]=fg=green,underline - ZSH_HIGHLIGHT_STYLES[global-alias]=fg=magenta - ZSH_HIGHLIGHT_STYLES[precommand]=fg=green,underline - ZSH_HIGHLIGHT_STYLES[commandseparator]=fg=blue,bold - ZSH_HIGHLIGHT_STYLES[autodirectory]=fg=green,underline - ZSH_HIGHLIGHT_STYLES[path]=underline - ZSH_HIGHLIGHT_STYLES[path_pathseparator]= - ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]= - ZSH_HIGHLIGHT_STYLES[globbing]=fg=blue,bold - ZSH_HIGHLIGHT_STYLES[history-expansion]=fg=blue,bold - ZSH_HIGHLIGHT_STYLES[command-substitution]=none - ZSH_HIGHLIGHT_STYLES[command-substitution-delimiter]=fg=magenta - ZSH_HIGHLIGHT_STYLES[process-substitution]=none - ZSH_HIGHLIGHT_STYLES[process-substitution-delimiter]=fg=magenta - ZSH_HIGHLIGHT_STYLES[single-hyphen-option]=fg=magenta - ZSH_HIGHLIGHT_STYLES[double-hyphen-option]=fg=magenta - ZSH_HIGHLIGHT_STYLES[back-quoted-argument]=none - ZSH_HIGHLIGHT_STYLES[back-quoted-argument-delimiter]=fg=blue,bold - ZSH_HIGHLIGHT_STYLES[single-quoted-argument]=fg=yellow - ZSH_HIGHLIGHT_STYLES[double-quoted-argument]=fg=yellow - ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]=fg=yellow - ZSH_HIGHLIGHT_STYLES[rc-quote]=fg=magenta - ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]=fg=magenta - ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]=fg=magenta - ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]=fg=magenta - ZSH_HIGHLIGHT_STYLES[assign]=none - ZSH_HIGHLIGHT_STYLES[redirection]=fg=blue,bold - ZSH_HIGHLIGHT_STYLES[comment]=fg=black,bold - ZSH_HIGHLIGHT_STYLES[named-fd]=none - ZSH_HIGHLIGHT_STYLES[numeric-fd]=none - ZSH_HIGHLIGHT_STYLES[arg0]=fg=green - ZSH_HIGHLIGHT_STYLES[bracket-error]=fg=red,bold - ZSH_HIGHLIGHT_STYLES[bracket-level-1]=fg=blue,bold - ZSH_HIGHLIGHT_STYLES[bracket-level-2]=fg=green,bold - ZSH_HIGHLIGHT_STYLES[bracket-level-3]=fg=magenta,bold - ZSH_HIGHLIGHT_STYLES[bracket-level-4]=fg=yellow,bold - ZSH_HIGHLIGHT_STYLES[bracket-level-5]=fg=cyan,bold - ZSH_HIGHLIGHT_STYLES[cursor-matchingbracket]=standout - fi -else - PROMPT='${debian_chroot:+($debian_chroot)}%n@%m:%~%# ' -fi -unset color_prompt - -precmd() { - # Print the previously configured title - print -Pnr -- "$TERM_TITLE" - print "" -} - -# enable color support of ls, less and man, and also add handy aliases -if [ -x /usr/bin/dircolors ]; then - test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" - alias ls='ls --color=auto' - alias grep='grep --color=auto' - alias fgrep='fgrep --color=auto' - alias egrep='egrep --color=auto' - alias diff='diff --color=auto' - alias ip='ip --color=auto' - - export LESS_TERMCAP_mb=$'\E[1;31m' # begin blink - export LESS_TERMCAP_md=$'\E[1;36m' # begin bold - export LESS_TERMCAP_me=$'\E[0m' # reset bold/blink - export LESS_TERMCAP_so=$'\E[01;33m' # begin reverse video - export LESS_TERMCAP_se=$'\E[0m' # reset reverse video - export LESS_TERMCAP_us=$'\E[1;32m' # begin underline - export LESS_TERMCAP_ue=$'\E[0m' # reset underline - - # Take advantage of $LS_COLORS for completion as well - zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" - zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' -fi - -# add snap to path -# export PATH=$PATH:/snap/bin - -# start x display server on logon -if [[ -z $DISPLAY ]] -then - startx -fi diff --git a/aliases.zsh b/aliases.zsh new file mode 100644 index 0000000..7b89d43 --- /dev/null +++ b/aliases.zsh @@ -0,0 +1,67 @@ +#!/usr/bin/false + +alias ll='ls -l' +alias la='ls -A' +alias l='ls -CF' + +alias pacman="sudo pacman" +alias apt="sudo apt" +alias dnf="sudo dnf" + +alias history="history 0" # force zsh to show the complete history + +alias docker=_docker +_docker() { + local args + args="" + + if [ "$1" = "runx" ] ; then + args="run -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix" + fi + + docker "$args" "$@" +} + +# lazy -- compiles and runs c/c++ in one go +alias lazy=_lazy +_lazy() { + local file + file=$1 + + cc $file -o "${file:0:-2}.out" -lm -g3 && gdb -q -ex run ./${file:0:-2}.out +} + +# create directory and set it as cwd +alias take=_take +_take() { + if [ -z "$1" ]; then + printf 'usage: %s directory' $0 > /dev/stderr + return 1 + fi + + mkdir -p $1 + cd $1 +} + +# compile markdown to html and view in browser +alias m=_m +_m() { + local file + local css + + file="$1" + css="$2" + + if [ -z "$file" ]; then + file="README.md" + print "Using $file as file" + fi + + if [ -z "$css" ]; then + css="$HOME/air.css" + print "Using $css as stylesheet" + fi + + pandoc "$file" -f gfm --css="$css" --self-contained --metadata title="$file" | { chromium-browser "data:text/html;base64,$(base64 -w 0)" &} +} + diff --git a/options.zsh b/options.zsh new file mode 100644 index 0000000..ad26045 --- /dev/null +++ b/options.zsh @@ -0,0 +1,49 @@ +#!/usr/bin/false + +#setopt autocd # change directory just by typing its name +#setopt correct # auto correct mistakes +setopt interactivecomments # allow comments in interactive mode +setopt magicequalsubst # enable filename expansion for arguments of the form ‘anything=expression’ +setopt nonomatch # hide error message if there is no match for the pattern +setopt notify # report the status of background jobs immediately +setopt numericglobsort # sort filenames numerically when it makes sense +setopt promptsubst # enable command substitution in prompt +color_prompt=yes # enable colors +WORDCHARS=${WORDCHARS//\/} # Don't consider certain characters part of the word +PROMPT_EOL_MARK="" # hide EOL sign ('%') + +# enable completion features +autoload -Uz compinit +compinit -d ~/.cache/zcompdump +zstyle ':completion:*:*:*:*:*' menu select +zstyle ':completion:*' auto-description 'specify: %d' +zstyle ':completion:*' completer _expand _complete +zstyle ':completion:*' format 'Completing %d' +zstyle ':completion:*' group-name '' +zstyle ':completion:*' list-colors '' +zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s +zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' +zstyle ':completion:*' rehash true +zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s +zstyle ':completion:*' use-compctl false +zstyle ':completion:*' verbose true +zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd' +zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" +zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' + +# History configurations +HISTFILE=~/.zsh_history +HISTSIZE=1000 +SAVEHIST=2000 +setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE +setopt hist_ignore_dups # ignore duplicated commands history list +setopt hist_ignore_space # ignore commands that start with space +setopt hist_verify # show command with history expansion to user before running it +setopt share_history # share command history data + + +# configure `time` format +TIMEFMT=$'\nreal\t%E\nuser\t%U\nsys\t%S\ncpu\t%P' + +# make less more friendly for non-text input files, see lesspipe(1) +#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" diff --git a/prompt.zsh b/prompt.zsh new file mode 100644 index 0000000..1b37505 --- /dev/null +++ b/prompt.zsh @@ -0,0 +1,13 @@ +#!/usr/bin/false + +configure_prompt() { + PROMPT=" 🐢 %F{240}%~ + $%f " + RPROMPT="%T - %?" +} + +precmd() { + # Print the previously configured title + print -Pnr -- "$TERM_TITLE" + print "" +}