-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot_bashrc
118 lines (103 loc) · 4.45 KB
/
dot_bashrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#
# ~/.bashrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
alias ls='ls --color=auto'
alias grep='grep --color=auto'
PS1='[\u@\h \W]\$ '
# My config
PS1='[\u@\h \w]\n\$ '
source /usr/share/doc/pkgfile/command-not-found.bash
export EDITOR=nvim
export XDG_CACHE_HOME=$HOME/.cache
export XDG_CONFIG_HOME=$HOME/.config
export XDG_DATA_HOME=$HOME/.local/share
export CARGO_HOME="$XDG_DATA_HOME"/cargo
export TEXMFHOME=$XDG_DATA_HOME/texmf
export TEXMFVAR=$XDG_CACHE_HOME/texlive/texmf-var
export TEXMFCONFIG=$XDG_CONFIG_HOME/texlive/texmf-config
alias anifps='gnome-randr modify --mode 3840x2160@23.976 DP-2'
alias cmcd="cd $XDG_DATA_HOME/chezmoi"
alias enven='env LANG=en_US.UTF-8 LANGUAGE=en_US'
alias hifps='gnome-randr modify --mode 3840x2160@119.993 DP-2'
alias less='less -R'
alias ll='ls -al --color=auto'
alias pacclear='paccache --remove && paccache --remove --uninstalled --keep 0'
alias pacrm='pacman -Qqd | paru -Rnsu -'
alias pacup='sudo pacman -Sy && paru -Su'
alias rebootwin='systemctl reboot --boot-loader-entry=auto-windows'
alias rm='gio trash'
alias updsrcinfo='makepkg --printsrcinfo | tee .SRCINFO'
alias vi='nvim'
alias vimdiff='nvim -d'
function setfps {
gnome-randr modify --mode 3840x2160@$1.${2:-000} DP-2
}
function zimu {
local filename=$1
local language_arg=$([ -n "$2" ] && echo "--language $2")
local device=${3:-$((RANDOM % 2))}
local gpu="gpu$4"
local hash=$(ffprobe -show_format -loglevel error "$filename" | b2sum | cut -d " " -f 1)
local hashed_audio_name=$hash.mkv
local hashed_log_name=$hash.log
local hashed_sub_name=$hash.srt
local filename_wo_extension="${filename%.*}"
if scp $gpu:subs/$hashed_sub_name "$filename_wo_extension.srt"; then
echo "Output subtitle file exists on remote. Subtitle downloaded."
ssh $gpu "rm audio/$hashed_audio_name subs/$hashed_sub_name subs/$hashed_log_name" &&
echo "Cleaned up server side leftover files."
if ssh $gpu systemctl --user list-units --type=service --quiet | grep --quiet running; then
echo "There are some other running user services on remote. Leaving them alone..."
return
fi
echo "No running tasks on remote. Disabling lingering..."
ssh $gpu loginctl disable-linger &&
echo "Disabled lingering."
return
fi
if ssh $gpu "test -e audio/$hashed_audio_name"; then
echo "Only audio file exists on remote."
if ssh $gpu systemctl --user list-units --type=service --quiet | grep --quiet running; then
echo "There are some running user services on remote. Seems still processing..."
return
fi
echo "But no running tasks on remote. Something is wrong."
echo "Please manually remove audio/$hashed_audio_name and try again."
echo "Disabling lingering since no tasks are running..."
ssh $gpu loginctl disable-linger &&
echo "Disabled lingering."
return
fi
[ ! -f "/tmp/$hashed_audio_name" ] && ffmpeg -loglevel warning -i "$filename" -map a -c copy "/tmp/$hashed_audio_name"
# Use `command` here to avoid local shell alias of `rm`.
scp /tmp/$hashed_audio_name $gpu:audio && command rm "/tmp/$hashed_audio_name" &&
# Apptainer can't load nvidia kernel modules themselves and will fail if the module is not loaded.
# Invoke `nvidia-smi` to load modules and sanity check if server GPUs are too busy.
# Usually when LANG contains "utf-8", `less` will support UTF-8.
# But when "UsePAM=no" was set in sshd_config, `/etc/locale.conf` was not parsed, and less won't
# support UTF-8. Thus, I'm using "LESSCHARSET=utf-8" here.
ssh -t $gpu -- loginctl enable-linger "&&" \
nvidia-smi "&&" \
touch subs/$hashed_log_name "&&" \
systemd-run --user -p "StandardOutput=truncate:\$HOME/subs/$hashed_log_name" \
env APPTAINERENV_CUDA_VISIBLE_DEVICES=$device \
apptainer run --nv \~/faster-whisper.sif \
--vad_filter True --vad_min_silence_duration_ms=5000 --model large-v2 --output_dir=\$HOME/subs --output_format=srt \
$language_arg \
\~/audio/$hashed_audio_name "&&" \
echo Not monitoring log.
# env LESSCHARSET=utf-8 less +F subs/$hashed_log_name
}
function zimuall {
local card=$((RANDOM % 2))
for folder in *; do
pushd "$folder"
for file in *; do
zimu "$file" "$folder" "$card"
card=$(( (card + 1) % 2 ))
done
popd
done
}