Skip to content

Instantly share code, notes, and snippets.

@megamen32
Last active February 27, 2026 16:36
Show Gist options
  • Select an option

  • Save megamen32/84da9b186f3b3a8c13c8fa1b030d084c to your computer and use it in GitHub Desktop.

Select an option

Save megamen32/84da9b186f3b3a8c13c8fa1b030d084c to your computer and use it in GitHub Desktop.
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# 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)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# some more ls aliases
alias ll='ls -alF'
alias la='ls -aA'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
. /usr/share/bash-completion/completions/systemctl 2>/dev/null || true
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
# Added by LM Studio CLI (lms)
export PATH="$PATH:/home/roomhacker/.lmstudio/bin"
# End of LM Studio CLI section
. "$HOME/.cargo/env"
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
eval "$(starship init bash)"
alias bat="batcat --paging=never"
#alias cat="batcat --paging=never"
alias lsb="exa -lah --git --icons"
eval "$(direnv hook bash)" #direnv — авто-переменные окружения по папкам
source "${HOME}/.atuin/bin/env" #поиск: Ctrl+R (становится сильно лучше). ранжирование, можно синхронизировать между машинами.
eval "$(zoxide init bash)" #cd на стероидах; ввел z запомнил папку& z foo cd into highest ranked directory matching foo
#source ~/.local/share/blesh/ble.sh
sys() { sudo systemctl --no-pager --plain "$@"; }
log() {
local unit="$1"
[[ -n "$unit" ]] || { echo "usage: log <unit> [journalctl-args...]"; return 2; }
shift
sudo journalctl -u "$unit" -f --no-pager "$@"
}
port() {
[[ -n "$1" ]] || { echo "usage: port <port>"; return 2; }
sudo lsof -i :"$1"
}
status() { sudo systemctl status --no-pager --plain "$@"; }
restart() {
local unit="$1"
[[ -n "$unit" ]] || { echo "usage: restart <unit>"; return 2; }
shift
sudo systemctl restart --no-pager --plain "$unit" "$@"
sudo systemctl --no-pager --plain status "$unit"
sudo journalctl -u "$unit" -f --no-pager
}
enable() { sudo systemctl enable --no-pager --plain "$@"; }
disable() { sudo systemctl disable --no-pager --plain "$@"; }
l() {
local unit="$1"
[[ -n "$unit" ]] || { echo "usage: l <unit> [journalctl-args...]"; return 2; }
shift
sudo journalctl -u "$unit" -f --no-pager "$@"
}
# completions (safe)
complete -F _systemctl sys status restart enable disable 2>/dev/null
complete -F _journalctl log l 2>/dev/null
s44(){ ssh 192.168.2.5; }
s88(){ ssh 192.168.2.75; }
ha(){ ssh 192.168.2.101; }
router(){ ssh root@192.168.2.1; }
vps(){ ssh root@vpn2.bezrabotnyi.com; }
venv(){ python3 -m venv "$@"; }
__auto_venv() {
# уже активировано — ничего не трогаем, если это то же самое место
local cwd="$PWD"
local target=""
if [[ -f "$cwd/.venv/bin/activate" ]]; then
target="$cwd/.venv"
elif [[ -f "$cwd/venv/bin/activate" ]]; then
target="$cwd/venv"
fi
# если есть target и он не активирован — активируем
if [[ -n "$target" ]]; then
if [[ "$VIRTUAL_ENV" != "$target" ]]; then
# если был другой venv — деактивируем
[[ -n "$VIRTUAL_ENV" ]] && deactivate 2>/dev/null
# shellcheck disable=SC1090
source "$target/bin/activate"
fi
return
fi
# если target нет, а venv активен и он был “папочным” — выключаем
if [[ -n "$VIRTUAL_ENV" ]]; then
case "$VIRTUAL_ENV" in
"$cwd/.venv"|"$cwd/venv") : ;; # остаёмся
*) deactivate 2>/dev/null ;;
esac
fi
}
# запускать на каждый prompt (после cd тоже сработает)
PROMPT_COMMAND="__auto_venv${PROMPT_COMMAND:+; $PROMPT_COMMAND}"
# --- systemd + fzf picker ----------------------------------------------------
# internal: list units (services by default; pass extra systemctl args if needed)
__service_list_units() {
# --all чтобы видеть и inactive/failed; без pager чтобы быстрее
systemctl list-unit-files --type=service --no-pager --no-legend 2>/dev/null \
| awk '{print $1}' \
| sed '/^$/d'
}
# Pick a unit with fzf. Usage: _service_pick [pattern]
_service_pick() {
local pattern="$1"
local unit
unit="$(__service_list_units | fzf --prompt='unit> ' --query="${pattern:-}" --height=40% --layout=reverse --border)"
[[ -n "$unit" ]] || return 1
printf '%s\n' "$unit"
}
# Main entry: service [pattern]
# After selecting a unit, choose an action: status/restart/enable/disable/log
service() {
local pattern="$1"
local unit action
unit="$(_service_pick "$pattern")" || return 1
action="$(printf '%s\n' status restart enable disable log | fzf --prompt="action($unit)> " --height=30% --layout=reverse --border)" || return 1
case "$action" in
status) sudo systemctl status --no-pager --plain "$unit" ;;
restart) sudo systemctl restart --no-pager --plain "$unit" && sudo systemctl status --no-pager --plain "$unit" ;;
enable) sudo systemctl enable --no-pager --plain "$unit" ;;
disable) sudo systemctl disable --no-pager --plain "$unit" ;;
log) sudo journalctl -u "$unit" -f --no-pager ;;
esac
}
# Quick actions without extra menu:
services() { local u="$(_service_pick "$1")" || return 1; sudo systemctl status --no-pager --plain "$u"; }
servicer() { local u="$(_service_pick "$1")" || return 1; sudo systemctl restart --no-pager --plain "$u"; sudo systemctl status --no-pager --plain "$u"; }
servicel() { local u="$(_service_pick "$1")" || return 1; sudo journalctl -u "$u" -f --no-pager; }
# --- systemd svc picker (enabled + active/sub + description) -----------------
__svc_rows() {
# output: UNIT<TAB>ENABLED<TAB>ACTIVE<TAB>SUB<TAB>DESCRIPTION
local TAB=$'\t'
# 1) Map unit-file state: unit -> enabled/disabled/static/...
# list-unit-files columns: UNIT FILE STATE VENDOR PRESET...
# take first two columns
awk -v TAB="$TAB" '{
if ($1 ~ /\.service$/) file[$1]=$2
}
END { for (u in file) print u TAB file[u] }
' < <(systemctl list-unit-files --type=service --no-legend --no-pager 2>/dev/null) \
| sort -t"$TAB" -k1,1 \
| awk -v TAB="$TAB" 'NR==FNR{file[$1]=$2; next}
{
# list-units columns: UNIT LOAD ACTIVE SUB DESCRIPTION...
unit=$1; active=$3; sub=$4;
desc="";
for (i=5;i<=NF;i++) desc=desc (i==5?"":" ") $i;
enabled=(unit in file ? file[unit] : "-");
print unit TAB enabled TAB active TAB sub TAB desc
}
' - <(systemctl list-units --type=service --all --no-legend --no-pager 2>/dev/null)
}
_svc_pick_pretty() {
local pattern="$1"
local TAB=$'\t'
local line unit
line="$(
__svc_rows | fzf \
--delimiter="$TAB" \
--with-nth=1,2,3,4,5 \
--prompt='unit> ' \
--query="${pattern:-}" \
--height=45% --layout=reverse --border \
--header=$'UNIT\tENABLED\tACTIVE\tSUB\tDESCRIPTION' \
--preview-window='right,60%,wrap' \
--preview='systemctl --no-pager --plain status {1} 2>/dev/null | sed -n "1,120p"'
)" || return 1
unit="${line%%$TAB*}"
[[ -n "$unit" ]] || return 1
printf '%s\n' "$unit"
}
svc() {
local unit action
unit="$(_svc_pick_pretty "$1")" || return 1
action="$(printf '%s\n' status restart enable disable log \
| fzf --prompt="action($unit)> " --height=30% --layout=reverse --border)" || return 1
case "$action" in
status) sudo systemctl status --no-pager --plain "$unit" ;;
restart) sudo systemctl restart --no-pager --plain "$unit" && sudo systemctl status --no-pager --plain "$unit" ;;
enable) sudo systemctl enable --no-pager --plain "$unit" ;;
disable) sudo systemctl disable --no-pager --plain "$unit" ;;
log) sudo journalctl -u "$unit" -f --no-pager ;;
esac
}
svcs() { local u="$(_svc_pick_pretty "$1")" || return 1; sudo systemctl status --no-pager --plain "$u"; }
svcr() { local u="$(_svc_pick_pretty "$1")" || return 1; sudo systemctl restart --no-pager --plain "$u"; sudo systemctl status --no-pager --plain "$u"; }
svcl() { local u="$(_svc_pick_pretty "$1")" || return 1; sudo journalctl -u "$u" -f --no-pager; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment