Added GNU Screen with its zsh integration plugin, a simple plugin loader for zsh, a `syntax-highlighting` and `autosuggestions` zsh plugins loaded from system

master
Meliurwen 3 years ago
parent 0c36d35d99
commit adf0773fd7
Signed by: meliurwen
GPG Key ID: 818A8B35E9F1CE10
  1. 2
      .dependencies/apt.list
  2. 67
      screen/.config/screen/bin/battery.sh
  3. 79
      screen/.config/screen/bin/netinfo.sh
  4. 22
      screen/.config/zsh/plugins/gnu_screen.zsh
  5. 28
      screen/.screenrc
  6. 36
      zsh/.zshrc

@ -11,6 +11,8 @@ nload
# Non-essential but very useful program
zsh
terminfo # ~/.zshrc dependency
zsh-syntax-highlighting # ZSH Plugin
zsh-autosuggestions # ZSH Plugin
iwconfig
haveged # Useful for some programs at boot that needs a good entropy

@ -0,0 +1,67 @@
#!/bin/sh
# Usage: ./battery.sh [--color [screen]]
if [ "$1" = "--color" ]; then
case $2 in
"screen")
colgreen="\005{g}"
colyellow="\005{y}"
colred="\005{r}"
colred_blink="\005{+B r}"
colend="\005{-}"
;;
"")
colgreen="\033[0;32m"
colyellow="\033[0;33m"
colred="\033[0;31m"
colred_blink="\033[5;31m"
colend="\033[0m"
;;
*)
printf "Color coding not supported. Aborting...\n"
exit 1
;;
esac
fi
pwr_lvl=""
status=""
multi_bat=0
for folder in /sys/class/power_supply/BAT?/; do
pwr_lvl="$(cat "$folder/capacity")"
pwr_stat="$(cat "$folder/status")"
if [ "$pwr_stat" = "Discharging" ]; then
status="%▼"
elif [ "$pwr_stat" = "Charging" ]; then
status="%▲"
elif [ "$pwr_stat" = "Not charging" ]; then
status="%~"
elif [ "$pwr_stat" = "Unknown" ]; then
status="%?"
else
status="%/"
fi
if [ "$1" = "--color" ]; then
# if:
# - <= 5 blinking red text
# - <= 10 red text
# - <= 20 yellow text
# - > 20 green
if [ "$pwr_lvl" -le 8 ]; then
color="${colred_blink}"
elif [ "$pwr_lvl" -le 20 ]; then
color="${colred}"
elif [ "$pwr_lvl" -le 40 ]; then
color="${colyellow}"
else
color="${colgreen}"
fi
fi
if [ $multi_bat = 1 ]; then
sep="|"
else
sep=""
multi_bat=1
fi
printf "%b%s%s%b%s" "${color}" "${pwr_lvl}" "${status}" "${colend}" "${sep}"
done

@ -0,0 +1,79 @@
#!/bin/sh
# Usage: ./netinfo.sh [--color [screen]]
if [ "$1" = "--color" ]; then
case $2 in
"screen")
colgreen="\005{g}"
colyellow="\005{y}"
colred="\005{r}"
colred_blink="\005{+B r}"
colend="\005{-}"
;;
"")
colgreen="\033[0;32m"
colyellow="\033[0;33m"
colred="\033[0;31m"
colred_blink="\033[5;31m"
colend="\033[0m"
;;
*)
printf "Color coding not supported. Aborting...\n"
exit 1
;;
esac
fi
wifi_str() {
wifi_signal="$(cat < /proc/net/wireless | grep "$1" | awk '{print $3}' | tr -d '.')"
bar=""
case $wifi_signal in
[0-1][0-9])
color=${colred}
bar="▂___"
;;
[2-3][0-9])
color=${colyellow}
bar="▂▄__"
;;
[4-5][0-9])
color=${colgreen}
bar="▂▄▆_"
;;
[6-7][0-9])
color=${colgreen}
bar="▂▄▆█"
;;
*)
color=${colred_blink}
bar="????"
;;
esac
printf "%b%s%b" "${color}" "${bar}" "${colend}"
}
IFACES="$(ip link show | awk '/^[0-9]+:/ {sub(/:/,"",$2); print $2","$9}')"
multi_ifce=0
for NET_IFACE in $IFACES ; do
[ "$(echo "$NET_IFACE" | cut -d ',' -f2)" = "DOWN" ] && continue
device="$(echo "$NET_IFACE" | cut -d ',' -f1)"
case $device in
wlp*)
[ $multi_ifce = 1 ] && STR_OUT="$STR_OUT|" || multi_ifce="1"
STR_OUT="$STR_OUT$(wifi_str "$device")"
;;
enp*)
[ $multi_ifce = 1 ] && STR_OUT="$STR_OUT|" || multi_ifce="1"
STR_OUT="$STR_OUT$device"
;;
usb*)
[ $multi_ifce = 1 ] && STR_OUT="$STR_OUT|" || multi_ifce="1"
STR_OUT="$STR_OUT$device"
;;
esac
done
printf "%s" "${STR_OUT}"

@ -0,0 +1,22 @@
#!/bin/zsh
# If the terminal is `screen` set a proper title and hardstatus
# See: https://gist.github.com/rampion/143727
if [[ $TERM == "screen" || $TERM == "screen-256color" ]]; then
function print_precmdexec() {
local tilded_home="$(printf %s "$PWD" | sed "s|^$HOME|~|")"
# set hardstatus of tab window (%h) for screen
printf '\e]0;%s\a' "[$tilded_home]:$1"
# set the tab window title (%t) for screen
printf '\ek%s\e\\' "$2"
}
# called by zsh before executing a command
function preexec() {
local cmd=(${(z)1}) # the command string
print_precmdexec "$cmd" "$cmd[1]:t"
}
# called by zsh before showing the prompt
function precmd() {
print_precmdexec "$SHELL:t" "$SHELL:t"
}
fi

@ -0,0 +1,28 @@
#!/bin/screen -c
# ~/.screenrc
# Docs: https://www.gnu.org/software/screen/manual/
startup_message off
altscreen on
term screen-256color
# Enables use of shift-PgUp and shift-PgDn
termcapinfo xterm*|rxvt*|kterm*|Eterm* ti@:te@
# Set the default size of the scrollback buffer for all windows
# Enter in copy mode `Ctrl+A [` and navigate with: PgUp/PgDn, arrows, vim keys
# or in some terminals also the mouse wheel
defscrollback 10000
# backtick id lifespan autorefresh cmd args...
backtick 1 10 10 $HOME/.config/screen/bin/battery.sh --color screen
backtick 2 10 10 $HOME/.config/screen/bin/netinfo.sh --color screen
# Statusbar
hardstatus on
hardstatus alwayslastline
hardstatus string '%-Lw%?%E%{= ck}%:%{= mk}%? %n%f %t %{-}%+Lw%{= dd}%=%{b}%D %d %M %c%=%{K}[%{y}Avg: %l%{K}][%1`%{K}][%2`]'
# Window captions
caption always
caption string '%?%F%{= gk}%:%{= wk}%? %n %?%F%{= Wk}%? %h%= '

@ -1,3 +1,6 @@
#!/bin/zsh
# ~/.zshrc
### History
HISTFILE="$HOME/.zsh_history"
HISTSIZE=500000000
@ -133,6 +136,11 @@ zstyle '*' single-ignored show
# automatically load bash completion functions
autoload -U +X bashcompinit && bashcompinit
zsh_asugg_path="/usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh"
zsh_shigh_path="/usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
[ -f "${zsh_asugg_path}" ] && . "${zsh_asugg_path}"
[ -f "${zsh_shigh_path}" ] && . "${zsh_shigh_path}"
unset zsh_asugg_path zsh_shigh_path
### Addons
# Colored manpages
@ -192,23 +200,33 @@ function zsh_git_theme() {
}
# Source: https://github.com/ohmyzsh/ohmyzsh/blob/master/lib/git.zsh
zsh_tmp_path="$zsh_base_dir/git.zsh"
zsh_tmp_path="$zsh_base_dir/plugins/git.zsh"
if [ -f "$zsh_tmp_path" ]; then
zsh_git_theme && \
source "$zsh_tmp_path" || echo "An error has occurred sourcing: $zsh_tmp_path"
zsh_git_theme
else
mkdir -p "$zsh_base_dir"
mkdir -p "$zsh_base_dir/plugins"
src_url='https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/lib/git.zsh'
echo "Downloading $src_url ..."
eval "curl -s --max-time 5 -o \""$zsh_tmp_path"\" \"$src_url\"" && \
unset src_url && \
zsh_git_theme && \
source "$zsh_tmp_path" || \
echo "[Warning] Failed to create the file or unrecheable URL: $src_url" && \
rmdir --ignore-fail-on-non-empty "$zsh_base_dir"
chmod +x "$zsh_tmp_path" && \
zsh_git_theme || \
echo "[Warning] Failed to create the file or unrecheable URL: $src_url"
fi
unfunction zsh_git_theme
# Rudimentary plugin loader
# Note: the files are loaded in alphabetical order
# Notes about the `(xEXN)`:
# - `.` plain files, should be comparable to a `-f` in a `find`
# - `@` symbolic links
# - `x`, `E`, `X` are respectively executable for owner, group and world
# - the `N` is a nullglob applied for the current pattern
# - See: https://zsh.sourceforge.io/Doc/Release/Expansion.html#Glob-Qualifiers
for plugin_f in "$zsh_base_dir/plugins/"*(.zsh|.zsh-theme)(xEXN); do
source $plugin_f || printf "An error has occurred sourcing: %s\n" "$plugin_f"
done
# For `prompt_subst` see:
# https://github.com/agnoster/agnoster-zsh-theme/pull/12
# Fork used:
@ -226,9 +244,7 @@ else
setopt prompt_subst && \
source "$zsh_tmp_path" || \
echo "[Warning] Failed to create the file or unrecheable URL: $src_url" && \
rmdir --ignore-fail-on-non-empty "$zsh_base_dir" && \
PS1="%B%{$fg[red]%}[%{$fg[yellow]%}%n%{$fg[green]%}@%{$fg[blue]%}%M %{$fg[magenta]%}%~%{$fg[red]%}]%{$reset_color%}$%b "
fi
unset zsh_tmp_path
unset zsh_base_dir

Loading…
Cancel
Save