Compare commits
10 Commits
50b8711d2a
...
410312a4a8
| Author | SHA1 | Date |
|---|---|---|
|
|
410312a4a8 | 4 weeks ago |
|
|
a54873573f | 2 months ago |
|
|
e646a2e308 | 2 months ago |
|
|
2db918a0a7 | 2 months ago |
|
|
4c048a3ea3 | 2 months ago |
|
|
5c2bcb9fca | 2 months ago |
|
|
91da5c1565 | 2 months ago |
|
|
bdc6478c30 | 2 months ago |
|
|
6665741686 | 2 months ago |
|
|
9ed4cea16c | 2 months ago |
@ -0,0 +1,20 @@
|
|||||||
|
# --- enable/disable this file ---
|
||||||
|
SRC_ENABLED=true
|
||||||
|
|
||||||
|
case "$SRC_ENABLED" in
|
||||||
|
1|true|yes|on) unset SRC_ENABLED ;; # enabled — clean up and continue
|
||||||
|
*) unset SRC_ENABLED; return ;; # disabled — clean up and skip this file
|
||||||
|
esac
|
||||||
|
# ---------------------------------
|
||||||
|
|
||||||
|
# Colored man pages
|
||||||
|
export LESS_TERMCAP_mb=$'\e[1;31m' # begin blinking — red (was green)
|
||||||
|
export LESS_TERMCAP_md=$'\e[1;33m' # begin bold — yellow (was blue, headings)
|
||||||
|
export LESS_TERMCAP_me=$'\e[0m' # end mode
|
||||||
|
export LESS_TERMCAP_se=$'\e[0m' # end standout-mode
|
||||||
|
export LESS_TERMCAP_so=$'\e[01;36m' # begin standout-mode — cyan (footer/status line, search hits)
|
||||||
|
export LESS_TERMCAP_ue=$'\e[0m' # end underline
|
||||||
|
export LESS_TERMCAP_us=$'\e[1;4;32m' # begin underline — green (was red)
|
||||||
|
|
||||||
|
export GROFF_NO_SGR=1
|
||||||
|
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
# --- enable/disable this file ---
|
||||||
|
SRC_ENABLED=true
|
||||||
|
|
||||||
|
case "$SRC_ENABLED" in
|
||||||
|
1|true|yes|on) unset SRC_ENABLED ;; # enabled — clean up and continue
|
||||||
|
*) unset SRC_ENABLED; return ;; # disabled — clean up and skip this file
|
||||||
|
esac
|
||||||
|
# ---------------------------------
|
||||||
|
|
||||||
|
swaptop()
|
||||||
|
{
|
||||||
|
local limit="${1:-10}"
|
||||||
|
local width="${2:-200}"
|
||||||
|
local p pid swap cmd
|
||||||
|
|
||||||
|
{
|
||||||
|
for p in /proc/[0-9]*; do
|
||||||
|
[ -r "$p/smaps" ] || continue
|
||||||
|
|
||||||
|
pid="${p##*/}"
|
||||||
|
|
||||||
|
swap=$(awk '
|
||||||
|
/^Swap:/ { swap += $2 }
|
||||||
|
/^SwapPss:/ { pss += $2; have_pss = 1 }
|
||||||
|
END {
|
||||||
|
if (have_pss)
|
||||||
|
print pss
|
||||||
|
else
|
||||||
|
print swap
|
||||||
|
}
|
||||||
|
' "$p/smaps" 2>/dev/null)
|
||||||
|
|
||||||
|
[ "${swap:-0}" -gt 0 ] || continue
|
||||||
|
|
||||||
|
cmd=$(tr '\0\t\n' ' ' < "$p/cmdline" 2>/dev/null)
|
||||||
|
|
||||||
|
if [ -z "$cmd" ]; then
|
||||||
|
cmd="[$(cat "$p/comm" 2>/dev/null)]"
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf '%d\t%s\t%s\n' "$swap" "$pid" "$cmd"
|
||||||
|
done
|
||||||
|
} |
|
||||||
|
sort -nr -k1,1 |
|
||||||
|
head -n "$limit" |
|
||||||
|
awk -F '\t' -v width="$width" '
|
||||||
|
BEGIN {
|
||||||
|
printf "%10s %7s %s\n", "SWAP", "PID", "COMMAND"
|
||||||
|
printf "%10s %7s %s\n", "----------", "-------", "-------"
|
||||||
|
}
|
||||||
|
{
|
||||||
|
line = sprintf("%9.1fM %7s %s", $1 / 1024, $2, $3)
|
||||||
|
|
||||||
|
if (length(line) > width)
|
||||||
|
line = substr(line, 1, width - 3) "..."
|
||||||
|
|
||||||
|
print line
|
||||||
|
}
|
||||||
|
'
|
||||||
|
}
|
||||||
@ -0,0 +1,218 @@
|
|||||||
|
# --- enable/disable this file ---
|
||||||
|
SRC_ENABLED=true
|
||||||
|
|
||||||
|
case "$SRC_ENABLED" in
|
||||||
|
1|true|yes|on) unset SRC_ENABLED ;; # enabled — clean up and continue
|
||||||
|
*) unset SRC_ENABLED; return ;; # disabled — clean up and skip this file
|
||||||
|
esac
|
||||||
|
# ---------------------------------
|
||||||
|
|
||||||
|
#
|
||||||
|
# pstree_compat.sh
|
||||||
|
#
|
||||||
|
# Meant to be sourced (e.g. from .bashrc). Defines functions only —
|
||||||
|
# sourcing this file must never print anything or execute pstree.
|
||||||
|
#
|
||||||
|
# Compatibility target: bash 3.2+ (RHEL 5) and bash 4.1 (Debian Squeeze).
|
||||||
|
#
|
||||||
|
# CAVEAT: this guard only protects against an old/wrong *bash*. If this
|
||||||
|
# file is sourced by a non-bash POSIX shell (e.g. dash as /bin/sh on
|
||||||
|
# Debian), the bashisms below (arrays, [[ ]], local -a) will cause a
|
||||||
|
# parse error at function-definition time, before any runtime check
|
||||||
|
# can run. Only source this from bash (.bashrc, not .profile/.sh).
|
||||||
|
#
|
||||||
|
# After sourcing, call:
|
||||||
|
# pstree_compat # root pid 1
|
||||||
|
# pstree_compat 1234 # specific pid
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# Returns 0 if running under bash >= 3.0, else prints an error to
|
||||||
|
# stderr and returns 1. Called at the top of every public entry point,
|
||||||
|
# never at source time.
|
||||||
|
#
|
||||||
|
bash_pstree_check_bash()
|
||||||
|
{
|
||||||
|
if [[ -z "$BASH_VERSION" ]]; then
|
||||||
|
printf 'pstree_compat: requires bash, current shell is not bash\n' >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
if [[ -z "${BASH_VERSINFO[0]}" ]] || (( BASH_VERSINFO[0] < 3 )); then
|
||||||
|
printf 'pstree_compat: requires bash >= 3.0 (found %s)\n' "$BASH_VERSION" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
pstree_compat()
|
||||||
|
{
|
||||||
|
bash_pstree_check_bash || return 1
|
||||||
|
|
||||||
|
local root_pid="${1:-1}"
|
||||||
|
if command -v pstree >/dev/null 2>&1; then
|
||||||
|
pstree -p "$root_pid"
|
||||||
|
else
|
||||||
|
bash_pstree "$root_pid"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Iterative (non-recursive) process tree walker.
|
||||||
|
# Avoids deep bash function recursion, which can blow the stack
|
||||||
|
# and crash the shell on large/deep process trees.
|
||||||
|
#
|
||||||
|
bash_pstree()
|
||||||
|
{
|
||||||
|
bash_pstree_check_bash || return 1
|
||||||
|
|
||||||
|
local root_pid="${1:-1}"
|
||||||
|
local procdir pid key value name ppid idx
|
||||||
|
|
||||||
|
PIDS=()
|
||||||
|
PPIDS=()
|
||||||
|
NAMES=()
|
||||||
|
idx=0
|
||||||
|
|
||||||
|
for procdir in /proc/[0-9]*; do
|
||||||
|
[[ -d "$procdir" ]] || continue
|
||||||
|
[[ -r "$procdir/status" ]] || continue
|
||||||
|
pid="${procdir#/proc/}"
|
||||||
|
name=""
|
||||||
|
ppid=""
|
||||||
|
while IFS=: read -r key value; do
|
||||||
|
value="${value#"${value%%[![:space:]]*}"}"
|
||||||
|
case "$key" in
|
||||||
|
Name) name="$value" ;;
|
||||||
|
PPid) ppid="$value" ;;
|
||||||
|
esac
|
||||||
|
done < "$procdir/status"
|
||||||
|
[[ -n "$ppid" ]] || continue
|
||||||
|
PIDS[$idx]="$pid"
|
||||||
|
PPIDS[$idx]="$ppid"
|
||||||
|
NAMES[$idx]="${name:-?}"
|
||||||
|
idx=$((idx + 1))
|
||||||
|
done
|
||||||
|
|
||||||
|
bash_pstree_set_chars
|
||||||
|
|
||||||
|
if ! bash_pstree_find_name "$root_pid" >/dev/null; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
bash_pstree_walk "$root_pid"
|
||||||
|
}
|
||||||
|
|
||||||
|
bash_pstree_set_chars()
|
||||||
|
{
|
||||||
|
local charmap
|
||||||
|
charmap=$(locale charmap 2>/dev/null)
|
||||||
|
if [[ "$charmap" == "UTF-8" ]]; then
|
||||||
|
BPT_VERT="│ "; BPT_TEE="├── "; BPT_LAST="└── "
|
||||||
|
else
|
||||||
|
BPT_VERT="| "; BPT_TEE="|-- "; BPT_LAST="\`-- "
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
bash_pstree_find_name()
|
||||||
|
{
|
||||||
|
local target="$1" i
|
||||||
|
for ((i = 0; i < ${#PIDS[@]}; i++)); do
|
||||||
|
if [[ "${PIDS[$i]}" == "$target" ]]; then
|
||||||
|
printf '%s' "${NAMES[$i]}"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Prints numerically-sorted children of $1, one per line.
|
||||||
|
# Called once per node during the iterative walk (not recursively).
|
||||||
|
#
|
||||||
|
bash_pstree_children()
|
||||||
|
{
|
||||||
|
local parent="$1" i list=""
|
||||||
|
for ((i = 0; i < ${#PIDS[@]}; i++)); do
|
||||||
|
if [[ "${PPIDS[$i]}" == "$parent" ]]; then
|
||||||
|
list="$list${PIDS[$i]}
|
||||||
|
"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
[[ -n "$list" ]] && printf '%s' "$list" | sort -n
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Iterative preorder walk using an explicit stack (three parallel
|
||||||
|
# arrays) instead of function recursion.
|
||||||
|
#
|
||||||
|
bash_pstree_walk()
|
||||||
|
{
|
||||||
|
local root_pid="$1"
|
||||||
|
local -a S_PID S_PRINT_PREFIX S_CHILD_PREFIX
|
||||||
|
local top pid print_prefix child_prefix name
|
||||||
|
local children child last_child new_prefix branch cont
|
||||||
|
local -a rev_children
|
||||||
|
local i n visited_guard=0
|
||||||
|
local max_iterations=200000 # safety valve against any /proc PPid cycle
|
||||||
|
|
||||||
|
S_PID=("$root_pid")
|
||||||
|
S_PRINT_PREFIX=("")
|
||||||
|
S_CHILD_PREFIX=("")
|
||||||
|
|
||||||
|
while [[ ${#S_PID[@]} -gt 0 ]]; do
|
||||||
|
visited_guard=$((visited_guard + 1))
|
||||||
|
if [[ $visited_guard -gt $max_iterations ]]; then
|
||||||
|
printf 'bash_pstree: aborting, too many nodes (possible /proc cycle)\n' >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
top=$((${#S_PID[@]} - 1))
|
||||||
|
pid="${S_PID[$top]}"
|
||||||
|
print_prefix="${S_PRINT_PREFIX[$top]}"
|
||||||
|
child_prefix="${S_CHILD_PREFIX[$top]}"
|
||||||
|
|
||||||
|
# pop
|
||||||
|
unset 'S_PID[top]' 'S_PRINT_PREFIX[top]' 'S_CHILD_PREFIX[top]'
|
||||||
|
S_PID=("${S_PID[@]}")
|
||||||
|
S_PRINT_PREFIX=("${S_PRINT_PREFIX[@]}")
|
||||||
|
S_CHILD_PREFIX=("${S_CHILD_PREFIX[@]}")
|
||||||
|
|
||||||
|
name=$(bash_pstree_find_name "$pid") || continue
|
||||||
|
printf '%s%s(%s)\n' "$print_prefix" "$name" "$pid"
|
||||||
|
|
||||||
|
children=$(bash_pstree_children "$pid")
|
||||||
|
[[ -n "$children" ]] || continue
|
||||||
|
|
||||||
|
last_child=$(printf '%s\n' "$children" | tail -n 1)
|
||||||
|
|
||||||
|
rev_children=()
|
||||||
|
n=0
|
||||||
|
while IFS= read -r child; do
|
||||||
|
[[ -n "$child" ]] || continue
|
||||||
|
rev_children[$n]="$child"
|
||||||
|
n=$((n + 1))
|
||||||
|
done <<< "$children"
|
||||||
|
|
||||||
|
for ((i = n - 1; i >= 0; i--)); do
|
||||||
|
child="${rev_children[$i]}"
|
||||||
|
if [[ "$child" == "$last_child" ]]; then
|
||||||
|
branch="$BPT_LAST"
|
||||||
|
cont="${child_prefix} "
|
||||||
|
else
|
||||||
|
branch="$BPT_TEE"
|
||||||
|
cont="${child_prefix}${BPT_VERT}"
|
||||||
|
fi
|
||||||
|
new_prefix="${child_prefix}${branch}"
|
||||||
|
|
||||||
|
S_PID+=("$child")
|
||||||
|
S_PRINT_PREFIX+=("$new_prefix")
|
||||||
|
S_CHILD_PREFIX+=("$cont")
|
||||||
|
done
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# NOTE: intentionally no code runs here. Sourcing this file must be a no-op
|
||||||
|
# other than defining the functions above.
|
||||||
|
|
||||||
|
alias pstree="pstree_compat"
|
||||||
|
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
# --- enable/disable this file ---
|
||||||
|
SRC_ENABLED=false
|
||||||
|
|
||||||
|
case "$SRC_ENABLED" in
|
||||||
|
1|true|yes|on) unset SRC_ENABLED ;; # enabled — clean up and continue
|
||||||
|
*) unset SRC_ENABLED; return ;; # disabled — clean up and skip this file
|
||||||
|
esac
|
||||||
|
# ---------------------------------
|
||||||
|
|
||||||
|
if [ "$HOSTNAME" = "$HOMEHOST" ]; then
|
||||||
|
. ~/.config/termclock.rc
|
||||||
|
|
||||||
|
mman() {
|
||||||
|
kitten @ --to unix:@manualy send-key --match 'var:role=termclock' ctrl+c
|
||||||
|
local CMD
|
||||||
|
printf -v CMD 'man %q' "$1"
|
||||||
|
printf '%s' "$CMD" | kitten @ --to unix:@manualy send-text --match 'var:role=termclock' --stdin
|
||||||
|
kitten @ --to unix:@manualy send-key --match 'var:role=termclock' enter
|
||||||
|
}
|
||||||
|
|
||||||
|
cman() {
|
||||||
|
kitten @ --to unix:@manualy send-key --match 'var:role=termclock' q
|
||||||
|
kitten @ --to unix:@manualy send-key --match 'var:role=termclock' ctrl+c
|
||||||
|
kitten @ --to unix:@manualy send-key --match 'var:role=termclock' ctrl+l
|
||||||
|
local CMD
|
||||||
|
printf -v CMD "TERM_CLOCK_COLOR=%q TERM_CLOCK_SYMBOL=%q TERM_CLOCK_SELF=%q TERM_CLOCK_NO_DAY=%q %s -g3" "$TERM_CLOCK_COLOR" "$TERM_CLOCK_SYMBOL" "$TERM_CLOCK_SELF" "$TERM_CLOCK_NO_DAY" "$TERM_CLOCK_CMD"
|
||||||
|
printf '%s' "$CMD" | kitten @ --to unix:@manualy send-text --match 'var:role=termclock' --stdin
|
||||||
|
kitten @ --to unix:@manualy send-key --match 'var:role=termclock' enter
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
# --- enable/disable this file ---
|
||||||
|
SRC_ENABLED=false
|
||||||
|
|
||||||
|
case "$SRC_ENABLED" in
|
||||||
|
1|true|yes|on) unset SRC_ENABLED ;; # enabled — clean up and continue
|
||||||
|
*) unset SRC_ENABLED; return ;; # disabled — clean up and skip this file
|
||||||
|
esac
|
||||||
|
# ---------------------------------
|
||||||
|
|
||||||
|
if [ "$HOSTNAME" = "$HOMEHOST" ]; then
|
||||||
|
# Nasourcujeme termclock
|
||||||
|
. ~/.config/termclock.rc
|
||||||
|
mman() {
|
||||||
|
PID=$(xdotool getwindowpid "$(xdotool search --classname manualy | head -n1)")
|
||||||
|
SESSION=$(qdbus6 "org.kde.konsole-$PID" | grep '^/Sessions/' | head -n1)
|
||||||
|
qdbus6 "org.kde.konsole-$PID" "$SESSION" org.kde.konsole.Session.sendText $'\003'
|
||||||
|
qdbus6 "org.kde.konsole-$PID" "$SESSION" org.kde.konsole.Session.runCommand "man $1"
|
||||||
|
}
|
||||||
|
cman() {
|
||||||
|
PID=$(xdotool getwindowpid "$(xdotool search --classname manualy | head -n1)")
|
||||||
|
SESSION=$(qdbus6 "org.kde.konsole-$PID" | grep '^/Sessions/' | head -n1)
|
||||||
|
qdbus6 "org.kde.konsole-$PID" "$SESSION" org.kde.konsole.Session.sendText "q"
|
||||||
|
qdbus6 "org.kde.konsole-$PID" "$SESSION" org.kde.konsole.Session.sendText $'\003'
|
||||||
|
qdbus6 "org.kde.konsole-$PID" "$SESSION" org.kde.konsole.Session.sendText $'\014'
|
||||||
|
qdbus6 "org.kde.konsole-$PID" "$SESSION" org.kde.konsole.Session.runCommand "TERM_CLOCK_COLOR='$TERM_CLOCK_COLOR' TERM_CLOCK_SYMBOL='$TERM_CLOCK_SYMBOL' TERM_CLOCK_SELF='$TERM_CLOCK_SELF' TERM_CLOCK_NO_DAY='$TERM_CLOCK_NO_DAY' $TERM_CLOCK_CMD -g3"
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
@ -0,0 +1,103 @@
|
|||||||
|
# --- enable/disable this file ---
|
||||||
|
SRC_ENABLED=true
|
||||||
|
|
||||||
|
case "$SRC_ENABLED" in
|
||||||
|
1|true|yes|on) unset SRC_ENABLED ;; # enabled — clean up and continue
|
||||||
|
*) unset SRC_ENABLED; return ;; # disabled — clean up and skip this file
|
||||||
|
esac
|
||||||
|
# ---------------------------------
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# hesgenk2() - generator hesel
|
||||||
|
# ZDROJ (puvodni forma): https://hesgen.rfa.cz/
|
||||||
|
# Celkova delka hesla = DelkaHesla + 2 cislice
|
||||||
|
# Poznamka: cislovani zacina od "0" :o)
|
||||||
|
# Modifikace - PeVa 24.06.2026 (shellcheck, futureproofing, code purge)
|
||||||
|
# Preveden na funkci pro sourcovani z .bashrc - kompatibilni s bash
|
||||||
|
# na RHEL5 (bash 3.2) a Debian Squeeze (bash 4.1) i novejsimi.
|
||||||
|
#
|
||||||
|
# Pouziti:
|
||||||
|
# hesgenk2 [PocetHesel] [DelkaHesla]
|
||||||
|
#
|
||||||
|
# Priklady:
|
||||||
|
# hesgenk2 -> 1 heslo, delka 12 (+2 cislice)
|
||||||
|
# hesgenk2 5 -> 5 hesel, delka 12 (+2 cislice)
|
||||||
|
# hesgenk2 5 16 -> 5 hesel, delka 16 (+2 cislice)
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
hesgenk2() {
|
||||||
|
# Napoveda
|
||||||
|
case "$1" in
|
||||||
|
-h|--help|help)
|
||||||
|
echo "Pouziti: hesgenk2 [PocetHesel] [DelkaHesla]"
|
||||||
|
echo
|
||||||
|
echo " PocetHesel pocet vygenerovanych hesel (cislo >= 1, vychozi 1)"
|
||||||
|
echo " DelkaHesla delka textove casti hesla (cislo >= 12, vychozi 12)"
|
||||||
|
echo " vysledne heslo ma DelkaHesla + 2 cislice na konci"
|
||||||
|
echo
|
||||||
|
echo "Priklady:"
|
||||||
|
echo " hesgenk2 -> 1 heslo, delka 12 (+2 cislice)"
|
||||||
|
echo " hesgenk2 5 -> 5 hesel, delka 12 (+2 cislice)"
|
||||||
|
echo " hesgenk2 5 16 -> 5 hesel, delka 16 (+2 cislice)"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Vychozi hodnoty
|
||||||
|
local PocetHesel=1
|
||||||
|
local DelkaHesla=12
|
||||||
|
|
||||||
|
# Parametry (bez ";", aby prazdny/nenumericky vstup neshodil shell)
|
||||||
|
local ParamPocet="${1:-0}"
|
||||||
|
local ParamDelka="${2:-0}"
|
||||||
|
ParamPocet=$((0 + ParamPocet))
|
||||||
|
ParamDelka=$((0 + ParamDelka))
|
||||||
|
|
||||||
|
if [ "$ParamPocet" -ge 1 ]; then
|
||||||
|
PocetHesel=$ParamPocet
|
||||||
|
fi
|
||||||
|
if [ "$ParamDelka" -ge 12 ]; then
|
||||||
|
DelkaHesla=$ParamDelka
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Pocet hesel: $PocetHesel, Delka $DelkaHesla"
|
||||||
|
echo
|
||||||
|
|
||||||
|
local Souhlasek=15
|
||||||
|
local SouhlaskaVelka
|
||||||
|
SouhlaskaVelka=("B" "C" "D" "F" "H" "J" "K" "L" "M" "N" "P" "R" "S" "T" "V")
|
||||||
|
local SouhlaskaMala
|
||||||
|
SouhlaskaMala=("b" "c" "d" "f" "h" "j" "k" "l" "m" "n" "p" "r" "s" "t" "v")
|
||||||
|
local Samohlasek=5
|
||||||
|
local SamohlaskaMala
|
||||||
|
SamohlaskaMala=("a" "e" "i" "o" "u")
|
||||||
|
|
||||||
|
local rot i RAND vystup
|
||||||
|
|
||||||
|
for rot in $(seq 1 "$PocetHesel"); do
|
||||||
|
# Reset
|
||||||
|
vystup=""
|
||||||
|
# TEXTOVA CAST HESLA
|
||||||
|
for i in $(eval "echo {0..$((DelkaHesla - 1))}"); do
|
||||||
|
if [ $((i % 2)) -eq 0 ]; then
|
||||||
|
# kazdy "sudy" znak je souhlaska
|
||||||
|
RAND=$((RANDOM % Souhlasek))
|
||||||
|
if [ $((i % 4)) -eq 0 ]; then
|
||||||
|
# kazdy "ctvrty" znak je velke pismeno
|
||||||
|
vystup="${vystup}${SouhlaskaVelka[$RAND]}"
|
||||||
|
else
|
||||||
|
vystup="${vystup}${SouhlaskaMala[$RAND]}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# kazdy "lichy" znak je samohlaska
|
||||||
|
RAND=$((RANDOM % Samohlasek))
|
||||||
|
vystup="${vystup}${SamohlaskaMala[$RAND]}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
RAND=$((RANDOM % 10))
|
||||||
|
vystup="${vystup}${RAND}"
|
||||||
|
RAND=$((RANDOM % 10))
|
||||||
|
vystup="${vystup}${RAND}"
|
||||||
|
echo "$vystup"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,76 @@
|
|||||||
|
# --- enable/disable this file ---
|
||||||
|
SRC_ENABLED=true
|
||||||
|
|
||||||
|
case "$SRC_ENABLED" in
|
||||||
|
1|true|yes|on) unset SRC_ENABLED ;; # enabled — clean up and continue
|
||||||
|
*) unset SRC_ENABLED; return ;; # disabled — clean up and skip this file
|
||||||
|
esac
|
||||||
|
# ---------------------------------
|
||||||
|
|
||||||
|
#!/bin/bash
|
||||||
|
# Simple one-line notes manager
|
||||||
|
# Compatible with bash 3.x (RHEL 5) and bash 4.1 (Debian Squeeze)
|
||||||
|
# NOTE: this file must be SOURCED, not executed:
|
||||||
|
# . ./notes.sh
|
||||||
|
# source ./notes.sh
|
||||||
|
|
||||||
|
NOTES_FILE="${NOTES_FILE:-$HOME/.notes}"
|
||||||
|
|
||||||
|
note_add() {
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
echo "Usage: note_add <text of note>" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
echo "$*" >> "$NOTES_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
notes() {
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
echo "Usage: notes"
|
||||||
|
echo " List all saved notes with their line numbers."
|
||||||
|
echo ""
|
||||||
|
echo "Related commands:"
|
||||||
|
echo " note_add <text> Add a new note"
|
||||||
|
echo " note_rm <line_number> Remove a note by its number"
|
||||||
|
echo ""
|
||||||
|
echo "Notes are stored in: $NOTES_FILE"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ ! -f "$NOTES_FILE" ] || [ ! -s "$NOTES_FILE" ]; then
|
||||||
|
echo "No notes yet."
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
awk '{ printf "%d: %s\n", NR, $0 }' "$NOTES_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
note_rm() {
|
||||||
|
num="$1"
|
||||||
|
|
||||||
|
if [ -z "$num" ]; then
|
||||||
|
echo "Usage: note_rm <line_number>" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! echo "$num" | grep -Eq '^[0-9]+$'; then
|
||||||
|
echo "Error: line number must be a positive integer" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$NOTES_FILE" ]; then
|
||||||
|
echo "Error: notes file not found" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
total=$(wc -l < "$NOTES_FILE" | tr -d ' ')
|
||||||
|
|
||||||
|
if [ "$num" -lt 1 ] || [ "$num" -gt "$total" ]; then
|
||||||
|
echo "Error: no note with that number" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
sed -i "${num}d" "$NOTES_FILE"
|
||||||
|
echo "Deleted note $num"
|
||||||
|
}
|
||||||
@ -0,0 +1,153 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# datum_tabulka.sh
|
||||||
|
# Vykresli ramecek s aktualnim datem/casem v cestine.
|
||||||
|
#
|
||||||
|
# Kompatibilita: bash 3.2+ (RHEL 5), coreutils/GNU sed jak jsou
|
||||||
|
# soucasti RHEL 5 a Debian Squeeze a novejsich. Nepouziva se zadny
|
||||||
|
# bashismus specificky pro bash 4+ (asociativni pole, ${var,,}, ...).
|
||||||
|
#
|
||||||
|
# POUZITI:
|
||||||
|
# 1) Spusteni jako samostatny skript:
|
||||||
|
# bash datum_tabulka.sh
|
||||||
|
#
|
||||||
|
# 2) "Nasourcovani" do interaktivniho shellu (napr. z ~/.bashrc),
|
||||||
|
# cimz se ziska prikaz "datum":
|
||||||
|
# echo 'source /cesta/k/datum_tabulka.sh' >> ~/.bashrc
|
||||||
|
# Po novem prihlaseni (nebo "source ~/.bashrc") pak staci
|
||||||
|
# napsat v terminalu:
|
||||||
|
# datum
|
||||||
|
#
|
||||||
|
# Pri sourcovani se nic samo nespusti - jen se definuje funkce
|
||||||
|
# "datum". Pri primem spusteni ("bash datum_tabulka.sh") se funkce
|
||||||
|
# rovnou i zavola.
|
||||||
|
|
||||||
|
# Pomocne funkce jsou prefixovany "_datum_", aby pri sourcovani do
|
||||||
|
# interaktivniho shellu nekolidovaly se jmeny jinych funkci/prikazu.
|
||||||
|
|
||||||
|
# Delka retezce v "znacich" (ne bajtech), nezavisla na locale:
|
||||||
|
# odstranime UTF-8 pokracovaci bajty (0x80-0xBF) a spocitame bajty,
|
||||||
|
# ktere zbyly - to odpovida poctu znaku bez ohledu na nastaveni LANG.
|
||||||
|
_datum_mb_len() {
|
||||||
|
printf '%s' "$1" | LC_ALL=C sed 's/[\x80-\xBF]//g' | LC_ALL=C wc -c | tr -d ' '
|
||||||
|
}
|
||||||
|
|
||||||
|
# Zopakuje znak $1 celkem $2 krat
|
||||||
|
_datum_repeat_char() {
|
||||||
|
local ch="$1"
|
||||||
|
local count="$2"
|
||||||
|
local out=""
|
||||||
|
local i=0
|
||||||
|
while [ "$i" -lt "$count" ]; do
|
||||||
|
out="${out}${ch}"
|
||||||
|
i=$((i + 1))
|
||||||
|
done
|
||||||
|
printf '%s' "$out"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Hlavni funkce - vypise tabulku s aktualnim datem/casem
|
||||||
|
datum() {
|
||||||
|
# --- Ceske nazvy mesicu (2. pad) a dnu v tydnu -------------------
|
||||||
|
# index 0 je jen vycpavka, aby indexy odpovidaly cislu mesice/dne
|
||||||
|
local mesice
|
||||||
|
mesice=(x ledna února března dubna května června července srpna září října listopadu prosince)
|
||||||
|
local dny
|
||||||
|
dny=(x Pondělí Úterý Středa Čtvrtek Pátek Sobota Neděle)
|
||||||
|
|
||||||
|
# --- Nacteni zivych dat jednim volanim date, aby byla konzistentni
|
||||||
|
# %Y rok, %m mesic, %d den, %H hodina, %M minuta, %Z zkratka pasma,
|
||||||
|
# %u den v tydnu (1=po..7=ne), %V ISO tyden, %j den v roce, %s epoch
|
||||||
|
local rok mesic den hod min pasmo dow tyden denroku epoch
|
||||||
|
set -- $(date +"%Y %m %d %H %M %Z %u %V %j %s")
|
||||||
|
rok=$1
|
||||||
|
mesic=$2
|
||||||
|
den=$3
|
||||||
|
hod=$4
|
||||||
|
min=$5
|
||||||
|
pasmo=$6
|
||||||
|
dow=$7
|
||||||
|
tyden=$8
|
||||||
|
denroku=$9
|
||||||
|
epoch=${10}
|
||||||
|
|
||||||
|
# --- Prevod cisel bez uvodnich nul (aby se neinterpretovaly jako 8)
|
||||||
|
local den_n mesic_n dow_n tyden_n denroku_n
|
||||||
|
den_n=$((10#$den))
|
||||||
|
mesic_n=$((10#$mesic))
|
||||||
|
dow_n=$((10#$dow))
|
||||||
|
tyden_n=$((10#$tyden))
|
||||||
|
denroku_n=$((10#$denroku))
|
||||||
|
|
||||||
|
# --- Kvartal --------------------------------------------------------
|
||||||
|
local kvartal
|
||||||
|
kvartal=$(( (mesic_n - 1) / 3 + 1 ))
|
||||||
|
|
||||||
|
# --- Obsahove radky tabulky ------------------------------------------
|
||||||
|
local radek1 radek2 radek3 radek4 radek5 radek6 radek7
|
||||||
|
radek1="${den_n}. ${mesice[$mesic_n]} ${rok}"
|
||||||
|
radek2="${dny[$dow_n]}, ${tyden_n}. týden"
|
||||||
|
radek3="${hod}:${min} ${pasmo}"
|
||||||
|
radek4=""
|
||||||
|
radek5="Q${kvartal}, ${denroku_n}. den v roce"
|
||||||
|
radek6=""
|
||||||
|
radek7="Unix čas: ${epoch}"
|
||||||
|
|
||||||
|
# --- Vypocet sirky tabulky (podle nejdelsiho radku + fixni pridani) -
|
||||||
|
# Sirka je vypoctena z nejdelsiho radku a pak natrvalo rozsirena o 5
|
||||||
|
# znaku. Protoze extra_sirka je konstanta, je vysledna sirka tabulky
|
||||||
|
# fixni napric spustenimi (meni se jen kvuli delce textu samotneho).
|
||||||
|
local extra_sirka=5
|
||||||
|
local max=0
|
||||||
|
local radek l
|
||||||
|
for radek in "$radek1" "$radek2" "$radek3" "$radek4" "$radek5" "$radek6" "$radek7"; do
|
||||||
|
l=$(_datum_mb_len "$radek")
|
||||||
|
if [ "$l" -gt "$max" ]; then
|
||||||
|
max=$l
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
max=$((max + extra_sirka))
|
||||||
|
|
||||||
|
# --- Vykreslovaci funkce (lokalni pres subshell, aby nezustaly) ------
|
||||||
|
_datum_print_border() {
|
||||||
|
local left="$1"
|
||||||
|
local right="$2"
|
||||||
|
printf '%s' "$left"
|
||||||
|
_datum_repeat_char "─" $((max + 2))
|
||||||
|
printf '%s\n' "$right"
|
||||||
|
}
|
||||||
|
|
||||||
|
_datum_print_line() {
|
||||||
|
local text="$1"
|
||||||
|
local len
|
||||||
|
len=$(_datum_mb_len "$text")
|
||||||
|
local pad=$((max - len))
|
||||||
|
printf '│ %s' "$text"
|
||||||
|
_datum_repeat_char " " "$pad"
|
||||||
|
printf ' │\n'
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Vykresleni tabulky ---------------------------------------------------
|
||||||
|
_datum_print_border "┌" "┐"
|
||||||
|
_datum_print_line "$radek1"
|
||||||
|
_datum_print_border "├" "┤"
|
||||||
|
_datum_print_line "$radek2"
|
||||||
|
_datum_print_line "$radek3"
|
||||||
|
_datum_print_line "$radek4"
|
||||||
|
_datum_print_line "$radek5"
|
||||||
|
_datum_print_line "$radek6"
|
||||||
|
_datum_print_border "├" "┤"
|
||||||
|
_datum_print_line "$radek7"
|
||||||
|
_datum_print_border "└" "┘"
|
||||||
|
|
||||||
|
# uklid pomocnych funkci definovanych uvnitr datum(), aby se
|
||||||
|
# neplichtily do jmenneho prostoru interaktivniho shellu
|
||||||
|
unset -f _datum_print_border _datum_print_line
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Spusteni jen pri primem volani skriptu, ne pri sourcovani -----------
|
||||||
|
# Pokud je soubor sourcovan (napr. z ~/.bashrc), pouze se definuje
|
||||||
|
# funkce "datum" a nic se nevypisuje. Pokud je soubor spusten primo
|
||||||
|
# (bash datum_tabulka.sh), funkce se rovnou zavola.
|
||||||
|
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
|
||||||
|
datum
|
||||||
|
fi
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
# --- enable/disable this file ---
|
||||||
|
SRC_ENABLED=true
|
||||||
|
|
||||||
|
case "$SRC_ENABLED" in
|
||||||
|
1|true|yes|on) unset SRC_ENABLED ;; # enabled — clean up and continue
|
||||||
|
*) unset SRC_ENABLED; return ;; # disabled — clean up and skip this file
|
||||||
|
esac
|
||||||
|
# ---------------------------------
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
alt + . # Cykluje parametry předchozích příkazů
|
||||||
|
^ck^kc^ # Nahradí ck za kc v předchozím příkazu a provede ho
|
||||||
|
!! # Předchozí příkaz
|
||||||
|
alias fuck="sudo $(history -p !!)" # Antistresové použití !!
|
||||||
|
mkdir -p tst/{1,2,3} # Vytvoří podadresáře 1 2 3 v adresáři tst
|
||||||
|
mkdir -ṕ tst/{1..10} # Vytvoří podadresáře 1 - 10 v adresáři tst
|
||||||
Loading…
Reference in new issue