[+] Fish (#7)

This commit is contained in:
2026-05-06 12:56:55 -04:00
committed by GitHub
parent f1bba8b7a5
commit 5a70fba83b
21 changed files with 1217 additions and 276 deletions
+8 -3
View File
@@ -1,8 +1,13 @@
#!/usr/bin/env bash
set -euo pipefail
if [[ $# -eq 0 ]]; then
echo "Usage: compress-7zst <7z args...>"
exit 1
fi
level="${level:-15}"
cores=$(python3 -c "import os; print(os.cpu_count())")
echo "Starting ZSTD compression with $cores cores and level $level"
# "$cmd" -I "zstd -T$cores -$level" --checkpoint=.1024 --totals --totals=SIGUSR1 -c -f "$@"
7z a -m0=zstd -mx"$level" -mmt"$cores" "$@"
exec 7z a -m0=zstd -mx"$level" -mmt"$cores" "$@"
-136
View File
@@ -1,136 +0,0 @@
#!/usr/bin/env python3
from __future__ import annotations
import os
import platform
import re
import shutil
from subprocess import Popen, check_call
import sys
import shlex
from datetime import datetime
from pathlib import Path
def comp(input: str = 'latest', proc: str = 'cpu', codec: str = 'x264', crf: int = 24, br: int = None,
cmd: bool = False, aargs: str = '', suffix: str = 'mp4'):
"""
Compress video
:param input: Input file (Default: latest)
:param proc: cpu (c) or gpu (g)
:param codec: x264 (4) or x265 (5)
:param crf: CRF (quality) for cpu encoding
:param cmd: Whether to output command directly
:param aargs: Additional args
:param suffix: File suffix (Default mp4)
:return:
"""
if input == 'latest':
rename()
i = sorted([s for s in os.listdir('.') if s.startswith('Rec') and s.endswith('mov')])[-1]
else:
i = input
proc = proc[0]
codec = {'4': {'c': 'x264', 'g': 'h264'}, '5': {'c': 'x265', 'g': 'hevc'}}[codec[-1]][proc]
out = i[:i.rindex('.')] + f'.{codec}'
if proc == 'c':
out += f'-{crf}'
out += f'.{suffix}'
c = ['ffmpeg', '-i', i]
if proc == 'c':
c += ['-c:v', f'lib{codec}', '-crf', str(crf)]
elif proc == 'g':
if platform.system() == 'Darwin':
c += ['-c:v', f'{codec}_videotoolbox']
else:
c += ['-c:v', f'{codec}_nvenc', '-cq', str(crf)]
else:
raise AssertionError(f'Processor is invalid ({codec}[0] not in "cg")')
if br:
c += ['-b:v', f'{br}k', '-maxrate', f'{br}k', '-bufsize', f'2M']
c += shlex.split(aargs) + [out]
print(c)
if not cmd:
Popen(c).wait()
def combine(format: str, output: str | Path):
"""
Combine videos
:param format: Regex pattern
:param output: Output file name
"""
pattern = re.compile(format)
# Find video files
print()
files = [f for f in os.listdir('.') if pattern.match(f)]
print(f'Combining these files: {files}')
if len(files) == 0:
return print('No files to combine')
# Write files to text
txt = Path('./temp.txt')
txt.write_text('\n'.join(f"file '{f}'" for f in files))
# Infer extension
if '.' not in output:
output = str(Path(output).with_suffix(Path(files[0]).suffix))
# Run FFmpeg
print('Running FFmpeg')
os.system(f'ffmpeg -f concat -safe 0 -i temp.txt -c copy {output}')
# Remove temprary file
os.remove(txt)
def rename():
for file in os.listdir('.'):
if file.startswith('Screen Recording ') or file.startswith('Screen Shot '):
pre = 'Rec' if 'Recording' in file else 'Shot'
end_index = (file.index('AM') if 'AM' in file else file.index('PM')) + 2
datestr = file[17 if pre == 'Rec' else 12:end_index]
dt = datetime.strptime(datestr, '%Y-%m-%d at %I.%M.%S %p')
date = dt.strftime(f'{pre} %Y-%m-%d %H-%M' + file[end_index:])
print(f'Renaming {file} to {date}')
os.rename(file, date)
def convert_gnome():
rec_dir = Path.home() / "Videos/Screencasts"
fs = [rec_dir / str(f) for f in os.listdir(rec_dir) if str(f).startswith("Screencast") and str(f).endswith(".webm")]
for inf in fs:
sp = inf.stem.split(" ")
ouf = rec_dir / f"Rec {sp[2]} {sp[3][:sp[3].rindex('-')]}.mp4"
if ouf.is_file():
print(f"Already converted: {inf}")
continue
print(f"Converting '{inf}' to '{ouf}'")
check_call(['ffmpeg', '-i', inf,
'-c:v', 'libx264',
'-vf', 'crop=trunc(iw/2)*2:trunc(ih/2)*2, fps=30',
'-y',
ouf])
if input("Remove files? [y/N]") == "y":
[os.remove(f) for f in fs]
if __name__ == '__main__':
args = sys.argv[1:]
if args:
v = eval(args[0])
if v:
print(v)
+3 -17
View File
@@ -1,25 +1,11 @@
if command -v pacman &> /dev/null; then
alias upgrade='sudo pacman -Syu'
alias upgrade="${ZSHRC_SUDO}pacman -Syu"
alias install='pacman -Sy'
alias uninstall='pacman -Rsn'
alias list-unused='pacman -Qdtq'
fi
if [ -f "/etc/arch-release" ]; then
# Java paths
export JDK8="/usr/lib/jvm/java-8-openjdk/"
export JDK11="/usr/lib/jvm/java-11-openjdk/"
export JDK17="/usr/lib/jvm/java-17-openjdk/"
export JDK18="/usr/lib/jvm/java-18-j9/"
export JDK19="/usr/lib/jvm/java-19-openjdk/"
alias java8="${JDK8}/bin/java"
alias java11="${JDK11}/bin/java"
alias java17="${JDK17}/bin/java"
alias java18="${JDK18}/bin/java"
alias java19="${JDK19}/bin/java"
export JAVA_HOME=${JDK17}
export PATH="${JDK17}/bin:$PATH"
export PATH="$HOME/.local/share/JetBrains/Toolbox/scripts:$PATH"
# GPG Init
@@ -32,8 +18,8 @@ if [ -f "/etc/arch-release" ]; then
# Free up cache
clean-cache() {
has yay && yay -Sc --noconfirm
has pacman && sudo pacman -Sc --noconfirm
has pacman && rm -rf /var/cache/pacman
has pacman && _zshrc_as_root pacman -Sc --noconfirm
has pacman && _zshrc_as_root rm -rf /var/cache/pacman
has paru && rm -rf "$HOME/.cache/paru"
has yarn && yarn cache clean
has conda && conda clean -a
+1 -17
View File
@@ -4,7 +4,7 @@ else
alias dc='docker compose'
fi
if [[ $OSTYPE != 'darwin'* ]]; then
if [[ $OSTYPE != 'darwin'* && $EUID -ne 0 ]]; then
alias docker="sudo docker"
alias docker-compose="sudo docker-compose"
fi
@@ -21,19 +21,3 @@ docker-compose-path()
docker inspect "$1" | grep "com.docker.compose.project.working_dir"
}
# Docker linux containers
alpine-create()
{
docker rmi azalea/alpine
docker run -it --name alpine-init --hostname alpine alpine \
/bin/sh -c 'apk add zsh bash git curl wget tar zstd python3 && bash <(curl -sL hydev.org/zsh)'
docker commit alpine-init azalea/alpine
docker rm alpine-init
}
alias alpine="docker start -ai alpine"
alias alpine-init="docker run -it --name alpine --hostname alpine azalea/alpine zsh"
alias psqlt+="docker run --rm -dit --name psql-test --hostname psql -e POSTGRES_HOST_AUTH_METHOD=trust postgres && echo 'Created'"
alias psqlt-="docker stop psql-test && echo 'Deleted'"
alias psqlt='psql -h $(docker-ip psql-test) -p 5432 -U postgres'
+95 -4
View File
@@ -1,7 +1,11 @@
# Git commit wrapper
commit() {
msg="$@"
git commit -m "$msg"
if [[ $# -eq 0 ]]; then
git commit
else
msg="$@"
git commit -m "$msg"
fi
}
commitall() {
@@ -44,18 +48,105 @@ git() {
fi
}
git-require-clean() {
command git rev-parse --is-inside-work-tree >/dev/null 2>&1 || return 1
if [[ -n "$(command git status --porcelain 2>/dev/null)" ]]; then
echo 'Workspace is not clean.'
command git status --short
return 1
fi
}
git-main-branch() {
local remote_head
remote_head=$(command git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null)
if [[ -n "$remote_head" ]]; then
echo "${remote_head#origin/}"
return 0
fi
local branch
for branch in main master trunk develop; do
if command git show-ref --verify --quiet "refs/heads/$branch"; then
echo "$branch"
return 0
fi
if command git show-ref --verify --quiet "refs/remotes/origin/$branch"; then
echo "$branch"
return 0
fi
done
echo 'Could not determine main branch.' >&2
return 1
}
git-update-main() {
local main_branch="$1"
if [[ -z "$main_branch" ]]; then
main_branch=$(git-main-branch) || return 1
fi
command git checkout "$main_branch" || return 1
command git pull --ff-only
}
br() {
if [[ $# -ne 1 ]]; then
echo 'Usage: br <branch-name>'
return 1
fi
local branch="$1"
git-require-clean || return 1
if command git show-ref --verify --quiet "refs/heads/$branch" || command git show-ref --verify --quiet "refs/remotes/origin/$branch"; then
command git checkout "$branch"
return $?
fi
local main_branch
main_branch=$(git-main-branch) || return 1
git-update-main "$main_branch" || return 1
command git checkout -b "$branch"
}
bru() {
local current_branch
current_branch=$(command git symbolic-ref --quiet --short HEAD 2>/dev/null)
if [[ -z "$current_branch" ]]; then
echo 'Could not determine current branch.'
return 1
fi
git-require-clean || return 1
local main_branch
main_branch=$(git-main-branch) || return 1
if [[ "$current_branch" == "$main_branch" ]]; then
echo "Already on $main_branch."
return 1
fi
git-update-main "$main_branch" || return 1
command git checkout "$current_branch" || return 1
command git rebase "$main_branch"
}
# Git environment
git-env() {
git_commands=( add bisect branch checkout clone commit diff fetch grep init log merge pull push rebase reset restore show status tag )
git_commands=( add bisect branch checkout clone commit diff fetch grep init log merge pull push rebase reset restore show stash tag )
for i in "${git_commands[@]}"
do
alias "$i"="git $i"
done
alias 'grm'='git rm'
alias 'gmv'='git mv'
alias 'st'='git status'
}
git-unenv() {
git_commands=( add bisect branch checkout clone commit diff fetch grep init log merge pull push rebase reset restore show status tag grm gmv )
git_commands=( add bisect branch checkout clone commit diff fetch grep init log merge pull push rebase reset restore show stash tag grm gmv st )
for i in "${git_commands[@]}"
do
unalias "$i"
-21
View File
@@ -1,21 +0,0 @@
# Cut videos - cut <file name> <end time> [start time (default 00:00:00)]
cutv() {
if [ "$#" -lt 2 ]; then
echo "Usage: cut <file name> <end time (hh:mm:ss)> [start time (00:00:00)]"
return 2
fi
local start="${3:-00:00:00}"
echo "$1"
echo "$2"
echo "$start"
ffmpeg -i "$1" -codec copy -ss "$start" -t "$2" Cut\ "$1"
}
alias vcomp="$BASEDIR/scripts/bin/video.py"
alias vcompy="ipython -i $BASEDIR/scripts/bin/video.py"
flac2mp3() {
for file in *.flac; do
ffmpeg -i "$file" -ab 320k -map_metadata 0 -id3v2_version 3 "${file%.flac}.mp3"
done
}
-35
View File
@@ -1,35 +0,0 @@
# Nixos only
if command -v nixos-rebuild &> /dev/null; then
alias rebuild="sudo nixos-rebuild switch"
alias gc="sudo nix-collect-garbage -d"
alias rebuild-gc="rebuild; gc"
# Update git
nix-git-update() {
pushd /etc/nixos
# Make sure there aren't any other changes
if git diff-index --quiet HEAD --; then
# No changes
update-nix-fetchgit *.nix
# If there are changes after updating
if ! git diff-index --quiet HEAD --; then
# Has changes
rebuild-gc
git add *.nix
git commit -m "[U] Update fetchgit refs"
git push
echo "Successfully updated fetchgit refs"
else
echo "There aren't any updates"
fi
else
# Changes
echo "Error: There are uncommitted changes"
git status
fi
popd
}
fi
+63 -43
View File
@@ -8,6 +8,20 @@ setopt SHARE_HISTORY
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
if [[ $EUID -eq 0 ]]; then
ZSHRC_SUDO=""
else
ZSHRC_SUDO="sudo "
fi
_zshrc_as_root() {
if [[ $EUID -eq 0 ]]; then
command "$@"
else
sudo "$@"
fi
}
BASEDIR="$(dirname "$(dirname "$0")")"
# Bash-like shortcuts
@@ -34,9 +48,10 @@ if command -v 'xdg-open' &> /dev/null; then
alias open="xdg-open"
fi
# 好用的简写w
# 好用的简写
alias ll='ls -l'
alias l='ll'
alias llg='ll --git --git-repos'
alias lla='ls -la'
alias grep='grep --color'
alias rm='rm -ir'
@@ -44,46 +59,66 @@ alias mkdirs='mkdir -p'
alias ip='ip -c -h -p'
alias ipa='ip -br a'
alias ipj='ip -j'
alias ipv4="curl https://1.0.0.1/cdn-cgi/trace -4 | grep ip"
alias ipv6="curl 'https://[2606:4700:4700::1111]/cdn-cgi/trace' -6 | grep ip"
alias ports='netstat -tulpn | grep LISTEN'
alias suports='sudo netstat -tulpn | grep LISTEN'
alias findtxt='grep -IHrnws --exclude=\*.log -s '/' -e'
ports() {
if command -v ss &> /dev/null; then
ss -tulpn
else
netstat -tulpn | grep LISTEN
fi
}
suports() {
if command -v ss &> /dev/null; then
_zshrc_as_root ss -tulpn
else
_zshrc_as_root netstat -tulpn | grep LISTEN
fi
}
findtxt() {
if [[ -z $1 ]]; then
echo "Usage: findtxt <pattern>"
return 1
fi
local pattern="$*"
if command -v rg &> /dev/null; then
rg -n --no-messages -- "$pattern" /
else
grep -IHrnws -s -e "$pattern" /
fi
}
alias clr='reset'
alias please='sudo'
alias tar-create='tar -cvf'
alias tar-expand='tar -zxvf'
if [[ "$IS_SANDBOX" == "1" ]]; then
alias codex='codex --dangerously-bypass-approvals-and-sandbox'
alias claude='claude --dangerously-skip-permissions'
fi
alias du='du -h'
alias sortsize='sort -hr'
alias dus='du -shc * | sortsize'
alias dusa='du -hc --max-depth=1 | sortsize'
alias ffmpeg="ffmpeg -hide_banner"
alias ffprobe="ffprobe -hide_banner"
alias ts='sudo tailscale'
alias ts="${ZSHRC_SUDO}tailscale"
alias ts-install='curl -fsSL https://tailscale.com/install.sh | sh'
alias vsucode='sudo code --user-data-dir /root/.config/vscode --no-sandbox'
alias visucode='EDITOR="code --wait" sudoedit'
alias gpu-temp='while sleep 1; do clear; gpustat; done'
alias cpu-temp='s-tui'
alias mount-external='sudo mount -t cifs //192.168.2.1/external /smb/external -o rw,user=azalea,uid=1000,gid=1000,pass='
alias compress-json="find -name '*.json' -print0 | parallel --jobs 80% -0 zstd -z -19 -v -f --rm {}"
alias ds-clean="find . -name '.DS_Store' -delete -print"
alias dotclean="find . -name '._*' -delete -print"
dotclean() {
find . \( -name '.DS_Store' -o -name '._*' \) -delete -print
}
alias clean-empty-dir="find . -type d -empty -delete -print"
alias restart-kwin="DISPLAY=:0 setsid kwin_x11 --replace"
alias mkfs.fat32="sudo mkfs.fat -F 32"
alias btrfs-fs-progress="sudo watch -d sudo btrfs fi us"
alias btrfs-balance-progress="sudo watch -d btrfs balance status"
alias mkfs.fat32="${ZSHRC_SUDO}mkfs.fat -F 32"
# Rsync aliases by 依云, for synching (keep hard links, ACL, atime, xattr, etc)
# Deletes files in destination that are not in source
@@ -135,6 +170,7 @@ upload-daisy() {
}
# Automatic sudo
if [[ $EUID -ne 0 ]]; then
alias sctl="sudo systemctl"
alias sctlu="systemctl --user"
alias jctl="sudo journalctl"
@@ -144,33 +180,17 @@ alias nginx="sudo nginx"
alias certbot="sudo certbot"
alias apt="sudo apt"
alias dpkg="sudo dpkg"
else
alias sctl="systemctl"
alias sctlu="systemctl --user"
alias jctl="journalctl"
alias jctlu="journalctl --user-unit"
fi
has() {
command -v "$1" &> /dev/null
}
# Compress 7z zstd <out_file> <in_files...>
compress-7zst() {
if [ -z "$1" ]; then
echo "Usage: compress-7zst <out_file> <in_files...>"
return
fi
7z a -m0=zstd -mx17 -mmt35 "$1" "$2"
}
# Install using system package manager
install-package() {
if has pacman; then
pacman -Sy "$1"
elif has apt; then
apt install "$1"
elif has dnf; then
dnf install "$1"
elif has brew; then
brew install "$1"
fi
}
ttmp() {
mkdir -p /tmp/tmp
cd /tmp/tmp || return
@@ -223,8 +243,8 @@ gradle() {
# Unix permissions reset (Dangerous! This will make executable files no longer executable)
reset-permissions-dangerous() {
sudo find . -type d -exec chmod 755 {} \;
sudo find . -type f -exec chmod 644 {} \;
_zshrc_as_root find . -type d -exec chmod 755 {} \;
_zshrc_as_root find . -type f -exec chmod 644 {} \;
}
export PATH="$SCR/bin:$PATH"