summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTill Höppner2017-05-15 14:32:03 +0200
committerTill Höppner2017-05-15 14:32:03 +0200
commit25cd8380f802b069f95d9514563aa2a083176925 (patch)
tree932cee39b430d984570842817d7f4649f6a33956
parentb2bf9b7a2d72f91d75f2222a70d54eaeb8b04d61 (diff)
downloadzsh-25cd8380f802b069f95d9514563aa2a083176925.tar.gz
zsh-25cd8380f802b069f95d9514563aa2a083176925.tar.xz
zsh-25cd8380f802b069f95d9514563aa2a083176925.zip
Add prompt and other conf.d
-rw-r--r--conf.d/00-user-config.zsh11
-rw-r--r--conf.d/10-options.zsh2
-rw-r--r--conf.d/60-prompt.zsh101
-rw-r--r--conf.d/70-completions.zsh8
-rw-r--r--conf.d/90-alias.zsh57
-rw-r--r--conf.d/90-history.zsh6
-rw-r--r--conf.d/99-youtube-dl.zsh20
7 files changed, 205 insertions, 0 deletions
diff --git a/conf.d/00-user-config.zsh b/conf.d/00-user-config.zsh
new file mode 100644
index 0000000..e075f17
--- /dev/null
+++ b/conf.d/00-user-config.zsh
@@ -0,0 +1,11 @@
+PRIMARY_USER=till
+
+if (($+commands[nvim])); then
+ EDITOR=nvim
+elif (($+commands[vim])); then
+ EDITOR=vim
+elif (($+commands[vi])); then
+ EDITOR=vi
+else
+ EDITOR=nano
+fi
diff --git a/conf.d/10-options.zsh b/conf.d/10-options.zsh
new file mode 100644
index 0000000..5d51789
--- /dev/null
+++ b/conf.d/10-options.zsh
@@ -0,0 +1,2 @@
+setopt nullglob # makes foo/* return "" if foo is empty, instead of an error
+
diff --git a/conf.d/60-prompt.zsh b/conf.d/60-prompt.zsh
new file mode 100644
index 0000000..ad86dd2
--- /dev/null
+++ b/conf.d/60-prompt.zsh
@@ -0,0 +1,101 @@
+bindkey -e # emacs-style keybindings
+
+setopt autocd
+
+setopt prompt_subst prompt_percent
+autoload colors && colors
+
+# wrap in %{%} to prevent zsh from counting the content towards
+# the text length, leading to over-compensation for zero-width characters
+zcol() {
+ echo -n "%{$@%}"
+}
+
+timestamp() {
+ echo $((`date "+%s + %N / 1e9"`))
+}
+
+elapsed() {
+ echo $(($(timestamp) - $command_start_time))
+}
+
+duration=0
+command_start_time=$(timestamp)
+# called just before line is evaluated
+preexec() {
+ command_start_time=$(timestamp)
+}
+
+# called just before prompt is updated which
+# is usually after the program ran, but also
+# on ^C or Enter on an empty line
+precmd() {
+ duration=$(elapsed)
+ command_start_time=$(timestamp)
+}
+
+git_prompt() {
+ local git_branch=$(git branch 2>/dev/null | grep \* | sed 's/* //')
+ # is in git repository if branch != ""
+ if [[ -n "$git_branch" ]]; then
+ # if no uncommitted changes
+ if git diff-index --quiet HEAD --; then
+ zcol "$fg[green]"
+ else
+ zcol "$fg[red]"
+ fi
+ echo -n "$git_branch "
+ fi
+}
+
+left_prompt() {
+ local last_status=$?
+
+ case $USER in
+ "$PRIMARY_USER" | "root") ;;
+ *) echo -n $USER
+ esac
+
+ if test -n "$SSH_TTY"; then
+ zcol "$fg[cyan]"
+ echo -n "@$(hostname | tr -d '\n') "
+ fi
+
+ zcol "$fg[green]"
+ { pwd; echo -n " " } | tr -d '\n' | sed -e "s:^$HOME:~:"
+
+ git_prompt
+
+ case $USER in
+ root) zcol "$fg[red]"; echo -n "# " ;;
+ *) zcol "$fg[blue]"; echo -n "> " ;;
+ esac
+
+ if [ "$last_status" -ne 0 ]; then
+ zcol "$fg_bold[red]"
+ echo -n "$last_status "
+ fi
+
+ zcol "$reset_color"
+}
+
+right_prompt() {
+ command_start_time=$(timestamp)
+ if (($duration > 0.99)); then
+ zcol "$fg_bold[cyan]"
+ printf "%.1fs" "$duration"
+ fi
+
+ zcol "$reset_color"
+}
+
+PROMPT='$(left_prompt)'
+RPROMPT='$(right_prompt)'
+
+bindkey "${terminfo[khome]}" beginning-of-line
+bindkey "${terminfo[kend]}" end-of-line
+
+bindkey '\eOA' history-substring-search-up # or ^[OA
+bindkey '\eOB' history-substring-search-down # or ^[OB
+
+export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE=fg=cyan
diff --git a/conf.d/70-completions.zsh b/conf.d/70-completions.zsh
new file mode 100644
index 0000000..50a6503
--- /dev/null
+++ b/conf.d/70-completions.zsh
@@ -0,0 +1,8 @@
+# 0 -- vanilla completion (abc => abc)
+# 1 -- smart case completion (abc => Abc)
+# 2 -- word flex completion (abc => A-big-Car)
+# 3 -- full flex completion (abc => ABraCadabra)
+zstyle ':completion:*' matcher-list '' \
+ 'm:{a-z\-}={A-Z\_}' \
+ 'r:[^[:alpha:]]||[[:alpha:]]=** r:|=* m:{a-z\-}={A-Z\_}' \
+ 'r:|?=** m:{a-z\-}={A-Z\_}'
diff --git a/conf.d/90-alias.zsh b/conf.d/90-alias.zsh
new file mode 100644
index 0000000..cb19c8e
--- /dev/null
+++ b/conf.d/90-alias.zsh
@@ -0,0 +1,57 @@
+alias s='nocorrect sudo '
+alias se='nocorrect sudo -E '
+alias sse='nocorrect sudo -sE '
+alias sudo='nocorrect sudo '
+alias just='nocorrect sudo '
+
+alias reboop=reboot
+
+alias g=git
+alias d=docker
+alias dc=docker-compose
+alias dm=docker-machine
+
+alias sc=systemctl
+alias scu='systemctl --user'
+alias jc=journalctl
+
+alias vim=$EDITOR
+alias e=$EDITOR
+
+ce() {
+ local file
+ file=$(find "$CFG_DIR" -type f 2>/dev/null | fzf +m) && e "$file"
+}
+
+alias c=cargo
+alias r=raco
+
+alias p=pass
+alias t=tungsten
+
+alias nib=nix-build
+alias nic=nix-channel
+alias nis=nix-shell
+alias nie=nix-env
+alias nir=nix-repl
+
+nih() {
+ nie -iA nixpkgs.coreEnv nixpkgs.desktopEnv nixpkgs.gamesEnv
+ dotfiles.coreEnv
+ dotfiles.desktopEnv
+}
+
+alias nor=nixos-rebuild
+alias noc=nixos-container
+
+alias pe=patchelf
+
+alias -g L='| less '
+alias -g F='| rg -i '
+alias -g X='| xargs '
+alias -g SDN=' >/dev/null '
+alias -g EDN=' 2>/dev/null '
+
+function steamrun() { # practically an alias, no?
+ LD_PRELOAD="libpthread.so.0 libGL.so.1" __GL_THREADED_OPTIMIZATIONS=1 primusrun $argv
+}
diff --git a/conf.d/90-history.zsh b/conf.d/90-history.zsh
new file mode 100644
index 0000000..596ddf2
--- /dev/null
+++ b/conf.d/90-history.zsh
@@ -0,0 +1,6 @@
+HISTFILE=~/.local/zsh/history
+mkdir -p $(dirname $HISTFILE)
+HISTSIZE=100000
+SAVEHIST=100000
+
+
diff --git a/conf.d/99-youtube-dl.zsh b/conf.d/99-youtube-dl.zsh
new file mode 100644
index 0000000..8e572a5
--- /dev/null
+++ b/conf.d/99-youtube-dl.zsh
@@ -0,0 +1,20 @@
+function download_audio() {
+ youtube-dl \
+ --extract-audio --audio-format vorbis --audio-quality 0 --no-call-home \
+ --restrict-filenames --ignore-errors --add-metadata $@
+}
+
+function rip() {
+ if [ "$#" -ne 1 ]; then
+ download_audio $(xclip -o)
+ else
+ download_audio $@
+ fi
+}
+
+function ripto() {
+ mkdir $1
+ pushd $1
+ rip $2
+ popd
+}