bin directory and vimrc comment

This commit is contained in:
wt
2024-07-05 13:25:21 +07:00
parent 04f05aad1b
commit 2307c4225c
12 changed files with 2515 additions and 15 deletions
View File
+11
View File
@@ -0,0 +1,11 @@
#!/usr/bin/env sh
HD=$1
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
echo "usage: $0 [HD]"
exit 0
fi
sudo hdparm -Tt $HD
Executable
+266
View File
@@ -0,0 +1,266 @@
#!/bin/sh
#
# fet.sh
# a fetch in pure POSIX shell
#
# supress errors
exec 2>/dev/null
set --
eq() { # equals | [ a = b ] with globbing
case $1 in
$2) ;;
*) return 1;;
esac
}
## DE
wm=$XDG_CURRENT_DESKTOP
[ "$wm" ] || wm=$DESKTOP_SESSION
## Distro
# freedesktop.org/software/systemd/man/os-release.html
# a common file that has variables about the distro
for os in /etc/os-release /usr/lib/os-release; do
# some POSIX shells exit when trying to source a file that doesn't exist
[ -f $os ] && . $os && break
done
if [ -e /proc/$$/comm ]; then
## Terminal
while [ ! "$term" ]; do
# loop over lines in /proc/pid/status until it reaches PPid
# then save that to a variable and exit the file
while read -r line; do
eq "$line" 'PPid*' && ppid=${line##*:?} && break
done < "/proc/${ppid:-$PPID}/status"
# Make sure not to do an infinite loop
[ "$pppid" = "$ppid" ] && break
pppid=$ppid
# get name of binary
read -r name < "/proc/$ppid/comm"
case $name in
*sh|"${0##*/}") ;; # skip shells
*[Ll]ogin*|*init|*systemd*) break;; # exit when the top is reached
# anything else can be assumed to be the terminal
# this has the side affect of catching tmux, but tmux
# detaches from the terminal and therefore ignoring that
# will just make the init the term
*) term=$name
esac
done
## WM/DE
[ "$wm" ] ||
# loop over all processes and check the binary name
for i in /proc/*/comm; do
read -r c < "$i"
case $c in
*bar*|*rc) ;;
awesome|xmonad*|qtile|sway|i3|[bfo]*box|*wm*) wm=${c%%-*}; break;;
esac
done
## Memory
# loop over lines in /proc/meminfo until it reaches MemTotal,
# then convert the amount (second word) from KB to MB
while read -r line; do
eq "$line" 'MemTotal*' && set -- $line && break
done < /proc/meminfo
mem="$(( $2 / 1000 ))MB"
## Processor
while read -r line; do
case $line in
vendor_id*) vendor="${line##*: } ";;
model\ name*) cpu=${line##*: }; break;;
esac
done < /proc/cpuinfo
## Uptime
# the simple math is shamefully stolen from aosync
IFS=. read -r uptime _ < /proc/uptime
d=$((uptime / 60 / 60 / 24))
up=$(printf %02d:%02d $((uptime / 60 / 60 % 24)) $((uptime / 60 % 60)))
[ "$d" -gt 0 ] && up="${d}d $up"
## Kernel
read -r _ _ version _ < /proc/version
kernel=${version%%-*}
eq "$version" '*Microsoft*' && ID="fake $ID"
## Motherboard // laptop
read -r model < /sys/devices/virtual/dmi/id/product_name
# invalid model handling
case $model in
# alternate file with slightly different info
# on my laptop it has the device model (instead of 'hp notebook')
# on my desktop it has the extended motherboard model
'System '*|'Default '*|'To Be Filled'*)
read -r model < /sys/devices/virtual/dmi/id/board_name
esac
## Packages
# clean environment, then make every file in the dir an argument,
# then save the argument count to $pkgs
set --
# kiss, arch, debian, void, gentoo
for i in '/var/db/kiss/installed/*' '/var/lib/pacman/local/[0-9a-z]*' \
'/var/lib/dpkg/info/*.list' '/var/db/xbps/.*' '/var/db/pkg/*/*'; do
set -- $i
[ $# -gt 1 ] && pkgs=$# && break
done
read -r host < /proc/sys/kernel/hostname
elif [ -f /var/run/dmesg.boot ]; then
# Both OpenBSD and FreeBSD use this file, however they're formatted differently
read -r bsd < /var/run/dmesg.boot
case $bsd in
Open*)
## OpenBSD cpu/mem/name
while read -r line; do
case $line in
'real mem'*)
# use the pre-formatted value which is in brackets
mem=${line##*\(}
mem=${mem%\)*}
;;
# set $cpu to everything before a comma and after the field name
cpu0:*)
cpu=${line#cpu0: }
# Remove excess info after the actual CPU name
cpu=${cpu%%,*}
# Set the CPU Manufacturer to the first word of the cpu
# variable [separated by '(' or ' ']
vendor=${cpu%%[\( ]*}
# We got all the info we want, stop reading
break
;;
# First 2 words in the file are OpenBSD <version>
*) [ "$ID" ] || { set -- $line; ID="$1 $2"; }
esac
done < /var/run/dmesg.boot
[ -d /var/db/pkg ] && set -- /var/db/pkg/* && pkgs=$#
read -r host < /etc/myname
host=${host%.*}
;;
# Everything else, assume FreeBSD (first line is ---<<BOOT>> or something)
*)
# shellcheck source=/dev/null
. /etc/rc.conf
# shut shellcheck up without disabling the warning
host=${hostname:-}
while read -r line; do
case $line in
# os version
FreeBSD*)
# If the OS is already set, no need to set it again
[ "$ID" ] && continue
ID=${line%%-R*}
;;
CPU:*)
cpu=${cpu#CPU: }
# Remove excess info from after the actual CPU name
cpu=${line%\(*}
;;
*Origin=*)
# CPU Manufacturer
vendor=${line#*Origin=\"}
vendor="${vendor%%\"*} "
;;
'real memory'*)
# Get the pre-formatted amount which is inside brackets
mem=${line##*\(}
mem=${mem%\)*}
# This appears to be the final thing we need from the file,
# no need to read it more.
break
esac
done < /var/run/dmesg.boot
;;
esac
elif v=/System/Library/CoreServices/SystemVersion.plist; [ -f "$v" ]; then
## Macos
# make sure this variable is empty as to not break the following loop
temp=
while read -r line; do
case $line in
# set a variable so the script knows it's on the correct line
# (the line after this one is the important one)
*ProductVersion*) temp=.;;
*)
# check if the script is reading the derired line, if not
# don't do anything
[ "$temp" ] || continue
# Remove everything before and including the first '>'
ID=${line#*>}
# Remove the other side of the XML tag, and insert the actual OS name
ID="MacOS ${ID%<*}"
# We got the info we want, end the loop.
break
esac
done < "$v"
fi
eq "$0" '*fetish' && printf 'Step on me daddy\n' && exit
# help i dont know if it's a capital consistently
eq "$wm" '*[Gg][Nn][Oo][Mm][Ee]*' && wm='foot DE'
## GTK
while read -r line; do
eq "$line" 'gtk-theme*' && gtk=${line##*=} && break
done < "${XDG_CONFIG_HOME:=$HOME/.config}/gtk-3.0/settings.ini"
# Shorten $cpu and $vendor
# this is so messy due to so many inconsistencies in the model names
vendor=${vendor##*Authentic}
vendor=${vendor##*Genuine}
cpu=${cpu##*) }
cpu=${cpu%% @*}
cpu=${cpu%% CPU}
cpu=${cpu##CPU }
cpu=${cpu##*AMD }
cpu=${cpu%% with*}
cpu=${cpu% *-Core*}
col() {
printf ' '
for i in 1 2 3 4 5 6; do
printf '\033[9%sm%s' "$i" "${colourblocks:-▅▅}"
done
printf '\033[0m\n'
}
print() {
[ "$2" ] && printf '\033[9%sm%6s\033[0m%b%s\n' \
"${accent:-4}" "$1" "${separator:- ~ }" "$2"
}
# default value
: "${info:=n user os sh wm up gtk cpu mem host kern pkgs term col n}"
for i in $info; do
case $i in
n) echo;;
os) print os "$ID";;
sh) print sh "${SHELL##*/}";;
wm) print wm "${wm##*/}";;
up) print up "$up";;
gtk) print gtk "${gtk# }";;
cpu) print cpu "$vendor$cpu";;
mem) print mem "$mem";;
host) print host "$model";;
kern) print kern "$kernel";;
pkgs) print pkgs "$pkgs";;
term) print term "$term";;
user) printf '%7s@%s\n' "$USER" "$host";;
col) col;;
esac
done
Executable
+4
View File
@@ -0,0 +1,4 @@
#!/bin/sh
ls --color /sys/class/net
Executable
+1958
View File
File diff suppressed because it is too large Load Diff
+5
View File
@@ -0,0 +1,5 @@
#!/bin/sh
killall waybar
waybar &
Executable
+233
View File
@@ -0,0 +1,233 @@
#!/bin/bash
_user_host(){
local username hostname
username="${USER:-$(id -un)}"
hostname="${HOSTNAME:-$(</etc/hostname)}"
userHost="$username@${hostname:-$(uname -n)}\n"
}
_uptime(){
local rawSeconds seconds days hours minutes
read -r rawSeconds _ </proc/uptime
seconds="${rawSeconds%.*}"
((days=seconds/86400))|| days=''
((hours=seconds%86400/3600))|| hours=''
((minutes=seconds%3600/60))|| minutes=''
days="${days:+$days days, }"
hours="${hours:+$hours hours, }"
minutes="${minutes:+$minutes minutes}"
uptime="${minutes:+\e[32mUptime\e[m: ${days}${hours}${minutes}\n}"
}
_kernel_arch(){
read -r kernel kernelRelease architecture < <(uname -srm)
architecture="${architecture:-$HOSTTYPE}"
kernelArch="${kernel:+\e[32mKernel\e[m: $kernel $kernelRelease $architecture\n}"
}
_operating_system(){
operatingSystem="${OSTYPE:-$(uname -o)}"
operatingSystem="${operatingSystem:+\e[32mOS\e[m: $operatingSystem\n}"
}
_cpu(){
local line processor freqDir curFreq maxFreq frequency
while read -r line; do
[[ $line =~ ^'model name' ]]&&{ processor="${line#*: }"; break; }
done </proc/cpuinfo
freqDir='/sys/devices/system/cpu/cpu0/cpufreq'
read -r maxFreq <"$freqDir/scaling_max_freq"
maxFreq="${maxFreq::2}"
: "${maxFreq#[0-9]}"
maxFreq="${maxFreq%[0-9]}.$_"
read -r curFreq <"$freqDir"/scaling_cur_freq
curFreq="${curFreq::2}"
: "${curFreq#0-9}"
curFreq="${curFreq%[0-9]}.$_"
frequency="${curFreq:+ $maxFreq@$curFreq}"
cpu="${processor:+\e[32mCPU\e[m: $processor $frequency\n}"
}
_gpu(){
local line
while read -r line; do
[[ $line =~ 'VGA'|'3D' ]]&&{ gpu="${line##*: }"; break; }
done < <(lspci)
gpu="${gpu:+\e[32mGPU\e[m: $gpu\n}"
}
_mobo(){
local moboDir moboVendor moboName
moboDir='/sys/devices/virtual/dmi/id'
read -r moboVendor <"$moboDir"/board_vendor
read -r moboName <"$moboDir"/board_name
mobo="${moboVendor:+\e[32mMobo\e[m: $moboVendor $moboName\n}"
}
_disk(){
local line blockPath blockDevice blockSize blocksTotal blocksAvailable diskModel rawDiskTotal diskTotal
while read -r line; do
[[ $line =~ '0 1'$ ]]&&{ blockPath="${line%% *}"; break; }
done </etc/fstab
blockDevice="${blockPath#/dev/}"
: "/sys/class/block/${blockDevice%[0-9]}/device/model"
[[ -f $_ ]]&& read -r diskModel <"$_"
read -r _ _ _ _ blockSize _ blocksTotal _ blocksAvailable _ _ < <(stat --file-system --terse /)
((partAvail=blockSize*blocksAvailable/1073741824))
((partTotal=blockSize*blocksTotal/1073741824))
((partUsed=partTotal-partAvail))
while read -r line; do
[[ $line =~ sda$ ]]&&{ line="${line% *}" rawDiskTotal="${line##* }"; break; }
done </proc/partitions
((diskTotal=rawDiskTotal/1048576))
disk="${partAvail:+\e[32mDisk\e[m: $diskModel $diskTotal $partUsed/$partTotal GiB\n}"
}
_ram(){
local line rawMemory memActive memTotal memUsage
while read -r line; do
case $line in
MemTot*) rawMemory=("${line#*: }");;
Active:*) rawMemory+=("${line#*:}"); break;;
esac
done </proc/meminfo
((memActive=${rawMemory[1]% kB}/1024))
((memTotal=${rawMemory[0]% kB}/1024))
memUsage="$(awk 'BEGIN{printf "%.0f\n", ('$memActive'/'$memTotal')*100}')%"
ram="${memUsage:+\e[32mRAM\e[m: $memActive/$memTotal MiB $memUsage\n}"
}
_kernel(){
local kernelName kernelRel
read -r kernelName _ kernelRel _ </proc/version
kernel="${kernelName:+\e[32mKernel\e[m: $kernelName $kernelRel\n}"
}
_distro(){
local line
while read -r line; do
[[ $line =~ ^'PRETTY'|^'NAME' ]]&&{
line="${line#*=}" distro="${line//\"}"; break
}
done </etc/os-release
distro="${distro:+\e[32mDistro\e[m: $distro\n}"
}
_genv(){
local line
genv="${XDG_CURRENT_DESKTOP:-$DESKTOP_SESSION}"
[[ ! $genv ]]&& hash wmctrl&&{
while read -r line; do
[[ $line =~ Name: ]]&&{ genv="${line#*: }"; break; }
done < <(wmctrl -m)
}
genv="${genv:+\e[32mGENV\e[m: $genv\n}"
}
_packages(){
local pkgCnt=0
pkgPath='/var/lib/pacman/local'
[[ -d $pkgPath ]]&&{
for _ in "$pkgPath"/*; do ((++pkgCnt)); done
}
packages="${pkgCnt:+\e[32mPackages\e[m: $pkgCnt\n}"
}
_swap(){
local line curSwap maxSwap
while read -ra line; do
(( ${i:=0} ))&&{
((curSwap+=line[3]/1024))
((maxSwap+=line[2]/1024))
}|| ((++i))
done </proc/swaps
swap="${curSwap:+\e[32mSwap\e[m: $curSwap/$maxSwap\n}"
}
main(){
_user_host
_uptime
_kernel_arch
_operating_system
_cpu
_gpu
_mobo
_disk
_ram
_kernel
_distro
_genv
_packages
_swap
printf '\e[?7l'
printf '%b' \
"$userHost" \
"$uptime" \
"$kernelArch" \
"$operatingSystem" \
"$cpu" \
"$gpu" \
"$mobo" \
"$disk" \
"$ram" \
"$kernel" \
"$distro" \
"$genv" \
"$packages" \
"$swap"
printf '\e[?7h'
}
stty -echo
if (( ${1:-0} > 0 )); then
trap 'printf "\e[?1049l"; stty echo; exit' 2
printf '\e[?1049h'
for((;;)){
printf '\e[2J\e[H'
main
sleep "$1"
}
else
main
fi
stty echo
+5
View File
@@ -1,4 +1,9 @@
#!/bin/sh
if [[ "$(id -u)" != "0" ]]; then
echo "You must be root"
exit 1
fi
ip route del default via 172.17.132.1 dev enp3s0
ip route add 172.17.0.0/24 via 172.17.132.1 dev enp3s0
-6
View File
@@ -1,6 +0,0 @@
#!/usr/bin/env sh
HD=$1
sudo hdparm -Tt $HD
+4 -4
View File
@@ -71,8 +71,8 @@ bind = $mainMod, right, movefocus, r
bind = $mainMod, up, movefocus, u
bind = $mainMod, down, movefocus, d
bind = $mainMod, J, movefocus, u
bind = $mainMod, K, movefocus, d
bind = $mainMod, J, movefocus, d
bind = $mainMod, K, movefocus, u
bind = $mainMod, H, movefocus, l
bind = $mainMod, L, movefocus, r
#---------------------------------------
@@ -83,8 +83,8 @@ bind = $mainMod SHIFT, right, movewindow, r
bind = $mainMod SHIFT, up, movewindow, u
bind = $mainMod SHIFT, down, movewindow, d
bind = $mainMod SHIFT, J, movewindow, u
bind = $mainMod SHIFT, K, movewindow, d
bind = $mainMod SHIFT, J, movewindow, d
bind = $mainMod SHIFT, K, movewindow, u
bind = $mainMod SHIFT, H, movewindow, l
bind = $mainMod SHIFT, L, movewindow, r
#---------------------------------------------
+26 -2
View File
@@ -9,11 +9,15 @@ set foldcolumn=2
set mouse=a
set encoding=utf8
set guifont=JetBrains\ Mono\ Nerd\ Font\ 11
"----- color scheme ---
colorscheme tokyonight
"----------------------
"-------- colorcolumn ------------------
set colorcolumn=110
highlight ColorColumn ctermbg=darkgray
"---------------------------------------
"-------------------- plugins ------------------------
call plug#begin()
Plug 'preservim/nerdtree'
Plug 'ryanoasis/vim-devicons'
@@ -32,13 +36,17 @@ call plug#begin()
Plug 'mxw/vim-jsx'
Plug 'theRealCarneiro/hyprland-vim-syntax'
call plug#end()
"-----------------------------------------------------
"--------- keybinds -------------------------
nnoremap <C-a> :NERDTreeFocus<CR>
inoremap <C-a> <Esc>:NERDTreeFocus<CR>
nnoremap <C-e> :NERDTree<CR>
nnoremap <C-q> :NERDTreeToggle<CR>
nnoremap <C-w> :NERDTreeToggle<CR>
inoremap <C-w> :NERDTreeToggle<CR>
nnoremap <C-g> :NERDTreeRefresh<CR>
inoremap <C-g> <Esc>:NERDTreeRefresh<CR>
"------------ tabs -----------------------
nnoremap <C-p> :tabprevious<CR>
nnoremap <C-n> :tabnext<CR>
nnoremap <C-t> :tabnew<CR>
@@ -47,7 +55,23 @@ inoremap <C-n> <Esc>:tabnext<CR>i
inoremap <C-t> <Esc>:tabnew<CR>
nnoremap <C-d> :tabclose<CR>
inoremap <C-d> <Esc>:tabclose<CR>
"-----------------------------------------
"----------------- term --------
nnoremap <C-x> :term<CR>
inoremap <C-x> <Esc>:term<CR>
"-------------------------------
"------------- gitlens -----------------------
nnoremap <C-l> :call ToggleGitLens()<CR>
inoremap <C-l> <Esc>:call ToggleGitLens()<CR>
"---------------------------------------------
nnoremap <C-s> :w<CR>
inoremap <C-s> <Esc>:w<CR>
nnoremap <C-q> :q<CR>
inoremap <C-q> <Esc>:q<CR>
"------------- vim-plug --------------
nnoremap <C-i> :PlugInstall<CR>
inoremap <C-i> <Esc>:PlugInstall<CR>
"-------------------------------------
nnoremap <C-u> :so%<CR>
inoremap <C-u> <Esc>:so%<CR>
"--------------------------------------------
+3 -3
View File
@@ -4,7 +4,7 @@
"spacing": 4,
"modules-left": ["custom/launcher", "cpu", "memory", "temperature", "disk", "custom/weather", "custom/updates", "custom/onscreenkeyboard", "hyprland/window"],
"modules-center": ["hyprland/workspaces"],
"modules-right": ["privacy", "mpris", "cava", "pulseaudio", "network", "backlight", "keyboard-state", "hyprland/language", "battery", "battery#bat2", "clock", "tray", "custom/power"],
"modules-right": ["privacy", "mpris", "pulseaudio", "network", "backlight", "keyboard-state", "hyprland/language", "battery", "battery#bat2", "clock", "tray", "custom/power"],
"hyprland/workspaces": {
"format": "{icon}",
// "format-icons": {
@@ -80,7 +80,7 @@
},
"network": {
"format-wifi": "{essid} ({signalStrength}%) 󰤨",
"format-ethernet": "{ipaddr}/{cidr} ",
"format-ethernet": "", //"{ipaddr}/{cidr} ",
"tooltip-format": "{ifname} via {gwaddr} ",
"format-linked": "{ifname} (No IP) ",
"format-disconnected": "Disconnected ⚠",
@@ -119,7 +119,7 @@
},
"disk": {
"interval": 30,
"format": " {free}",
"format": " {used}/{free}",
"unit": "GB"
},
"custom/spotify": {