[hypnos] 重构 home 下 dotfiles 独立目录结构

This commit is contained in:
2026-01-23 01:20:06 +08:00
parent 2f31fbcd6e
commit 91a6a981c2
14 changed files with 47 additions and 12 deletions
+1 -4
View File
@@ -5,10 +5,7 @@
defaultSopsFile = ../../secrets/ssh-config.yaml;
};
home.file.".ssh" = {
source = ./ssh;
recursive = true;
};
home.file = lib.origami404.standaloneToHome ".ssh";
home.activation.sshDirPerms = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
if [ -d "$HOME/.ssh" ]; then
-1
View File
@@ -1 +0,0 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJyrUiSdpTC+vP+pNDChehLG+ChYL2By2LtjmVJiHmaf origami@eris
+3 -5
View File
@@ -8,10 +8,8 @@
};
home.shell.enableZshIntegration = true;
home.file.".zsh.d" = {
source = ./zsh/.zsh.d;
recursive = true;
};
home.file.".zshrc.o4".source = ./zsh/.zshrc;
home.file =
(lib.origami404.standaloneToHome ".zsh.d")
// (lib.origami404.standaloneToHome { rel = ".zshrc"; realpath = ".zshrc.o4"; });
programs.zsh.initContent = "source $HOME/.zshrc.o4";
}
-58
View File
@@ -1,58 +0,0 @@
# Complete filename by modification time
zstyle ':completion:*' file-sort modification
# FZF shell integration
source <(fzf --zsh)
if command -v bat &> /dev/null; then
# Preview file content using bat (https://github.com/sharkdp/bat)
export FZF_CTRL_T_OPTS="
--walker-skip .git,node_modules,target
--preview 'bat -n --color=always {}'
--bind 'ctrl-/:change-preview-window(down|hidden|)'"
fi
if command -v tree &> /dev/null; then
# Preview directory tree using tree
export FZF_ALT_C_OPTS="
--walker-skip .git,node_modules,target
--preview 'tree -C {} | head -200'"
fi
# FZF Fuzzy completion
export FZF_COMPLETION_TRIGGER=''
bindkey -r '^P'
bindkey -r '^I'
bindkey '^P' fzf-completion
bindkey '^I' $fzf_default_completion
# Options to fzf command
export FZF_COMPLETION_OPTS='--border --info=inline'
if command -v fd &> /dev/null; then
# Use fd (https://github.com/sharkdp/fd) for listing path candidates.
# - The first argument to the function ($1) is the base path to start traversal
# - See the source code (completion.{bash,zsh}) for the details.
_fzf_compgen_path() {
fd --hidden --follow --exclude ".git" . "$1"
}
# Use fd to generate the list for directory completion
_fzf_compgen_dir() {
fd --type d --hidden --follow --exclude ".git" . "$1"
}
fi
# Advanced customization of fzf options via _fzf_comprun function
# - The first argument to the function is the name of the command.
# - You should make sure to pass the rest of the arguments to fzf.
_fzf_comprun() {
local command=$1
shift
case "$command" in
cd) fzf --preview 'tree -C {} | head -200' "$@" ;;
export|unset) fzf --preview "eval 'echo \$'{}" "$@" ;;
ssh) fzf --preview 'dig {}' "$@" ;;
*) fzf --preview 'bat -n --color=always {}' "$@" ;;
esac
}
-146
View File
@@ -1,146 +0,0 @@
cmake-llvm () {
local cmake_args=("-G" "Ninja")
# find cmake root dir
# if defined PROJECT or P, use it as project root
# if within git (git rev-parse --is-inside-work-tree), use git rev-parse --show-toplevel
# if setted LLVM_ROOT, use it
# default "../llvm", if not exist, error
local llvm_root=".."
if [ -n "${PROJECT}" ]; then
llvm_root="${PROJECT}"
elif [ -n "${P}" ]; then
llvm_root="${P}"
elif git rev-parse --is-inside-work-tree &> /dev/null; then
llvm_root=$(git rev-parse --show-toplevel)
elif [ -n "${LLVM_ROOT}" ]; then
llvm_root="${LLVM_ROOT}"
fi
if [ ! -d "${llvm_root}/llvm" ]; then
echo "Error: not inside a llvm directory"
return 1
fi
cmake_args+=("${llvm_root}/llvm")
# Set build_type from arg[1]
local build_type="${1}"
if [ -z "${build_type}" ]; then
echo "Error: build_type is empty"
return 1
fi
cmake_args+=("-DCMAKE_BUILD_TYPE=${build_type}")
# check LLVM_PROJECTS env
if [ -z "${LLVM_PROJECTS}" ]; then
echo "Error: LLVM_PROJECTS env is not set"
return 1
fi
cmake_args+=("-DLLVM_ENABLE_PROJECTS=${LLVM_PROJECTS}")
# check LLVM_TARGETS
if [ -z "${LLVM_TARGETS}" ]; then
echo "Error: LLVM_TARGETS env is not set"
return 1
fi
cmake_args+=("-DLLVM_TARGETS_TO_BUILD=${LLVM_TARGETS}")
# if setted LLVM_COMPILER, use it, else default clang
if [ -z "${LLVM_COMPILER}" ]; then
# if setted CMAKE_C_COMPILER or CMAKE_CXX_COMPILER, use it, else default clang
cmake_args+=(
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER:-clang}"
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER:-clang++}"
)
elif [ "${LLVM_COMPILER}" == "gcc" ]; then
cmake_args+=("-DCMAKE_C_COMPILER=gcc" "-DCMAKE_CXX_COMPILER=g++")
elif [ "${LLVM_COMPILER}" == "clang" ]; then
cmake_args+=("-DCMAKE_C_COMPILER=clang" "-DCMAKE_CXX_COMPILER=clang++")
else
echo "Error: LLVM_COMPILER is invalid"
return 1
fi
# if not setted LLVM_NO_*, use default optimized options
if [ -z "${LLVM_NO_SHARED}" ]; then
cmake_args+=("-DBUILD_SHARED_LIBS=On")
fi
if [ -z "${LLVM_APPEND_VC_REV}"]; then
cmake_args+=("-DLLVM_APPEND_VC_REV=Off")
fi
if [ -z "${LLVM_NO_LLD}" ]; then
cmake_args+=("-DLLVM_ENABLE_LLD=On")
fi
if [ -z "${LLVM_NO_OPT_TABLEGEN}" ]; then
cmake_args+=("-DLLVM_OPTIMIZED_TABLEGEN=On")
fi
if [ -z "${LLVM_NO_SPLIT_DWARF}" ]; then
cmake_args+=("-DLLVM_USE_SPLIT_DWARF=On")
fi
cmake_args+=("-DCMAKE_EXPORT_COMPILE_COMMANDS=On")
# append args[2:] to cmake_args
cmake_args+=("${@:2}")
# print cmake args, one for each line
# and ask for confirmation
for arg in "${cmake_args[@]}"; do
echo "${arg}"
done
read "?Press enter to continue?"
# run cmake with cmake_args
cmake "${cmake_args[@]}"
}
git-local-exclude () {
local file="${1}"
# if file is empty, exit
if [ -z "${file}" ]; then
echo "Error: file is empty"
return 1
fi
# if .git/info/exclude not exist, exit
if [ ! -f .git/info/exclude ]; then
echo "warning: .git/info/exclude not exist, maybe in other worktree?"
return 1
fi
echo "${file}" >> .git/info/exclude
}
generate-local-dir () {
if git rev-parse --is-inside-work-tree &> /dev/null; then
project_root=$(git rev-parse --show-toplevel)
else
echo "Error: not inside a git repository"
return 1
fi
pushd "${project_root}"
git-local-exclude .local
mkdir -p .local
mkdir -p .local/bin
touch .local/notes.md
cat > .local/env.sh << EOF
export P="${project_root}"
export D="\$P/build-debug/bin"
export R="\$P/build-release/bin"
export L="\$P/.local"
export PATH="\$L/bin:\$PATH"
EOF
git-local-exclude .vscode
mkdir -p .vscode
if [ -f .vscode/settings.json ]; then
echo "Warning: .vscode/settings.json already exist"
else
echo '{}' > .vscode/settings.json
fi
popd
}
File diff suppressed because it is too large Load Diff
-24
View File
@@ -1,24 +0,0 @@
# From https://serverfault.com/a/1064320
ssh2config() {
host="$(ssh -G "$@" | sed -n 's/^hostname //p')"
echo "$host"
comm -23 <(ssh -G "$@" | sort) <(ssh -G abcddd | sort) | sed 's/^/ /'
echo ''
}
backlight() {
#echo $1 | sudo tee /sys/class/backlight/intel_backlight/brightness
echo $1 | sudo tee /sys/class/backlight/amdgpu_bl1/brightness
}
gpg-login() {
export GPG_TTY=$(tty)
echo "test" | gpg --clearsign > /dev/null 2>&1
}
alias ipy='ipython'
alias ts4='tailscale ip -4'
alias ts6='tailscale ip -6'
alias x='atool -x'
alias pc='proxychains'
-33
View File
@@ -1,33 +0,0 @@
# if bat is installed, alias cat to it
if command -v bat &> /dev/null; then
alias cat='bat'
alias pcat='/usr/bin/cat'
fi
# if eza is installed, alias ls to it; also check exa
if command -v eza &> /dev/null; then
alias ls='eza'
elif command -v exa &> /dev/null; then
alias ls='exa'
fi
alias ll='ls -l'
alias la='ls -a'
# if fd is installed, alias find to it
if command -v fd-find &> /dev/null; then
alias fd='fd-find'
fi
if command -v fd &> /dev/null; then
alias find='fd'
fi
# if rg is installed, alias grep to it
if command -v ripgrep &> /dev/null; then
alias rg='rgrep'
fi
if command -v rg &> /dev/null; then
alias grep='rg'
fi
# Compatibility with windows
alias traceroute='tracert'
-38
View File
@@ -1,38 +0,0 @@
#!/usr/bin/env zsh
sops-update-file() {
local src_file="$1"
local yaml_file="$2"
local age_key_file="$HOME/.config/sops/age/keys.txt"
if [[ -z "$src_file" || -z "$yaml_file" ]]; then
echo "用法: sops-update-file <原文件> <yaml文件>" >&2
return 1
fi
if [[ ! -f "$src_file" ]]; then
echo "找不到原文件: $src_file" >&2
return 1
fi
if [[ ! -f "$age_key_file" ]]; then
echo "找不到 age 私钥: $age_key_file" >&2
return 1
fi
local key_name="${yaml_file:t:r}"
local age_pub
age_pub="$(nix-shell -p age --run "age-keygen -y $age_key_file")" || return 1
local tmp
tmp="$(mktemp /tmp/sops-update.XXXXXX.yaml)" || return 1
{
echo "${key_name}: |"
sed 's/^/ /' "$src_file"
} > "$tmp"
nix-shell -p sops --run "sops --encrypt --input-type yaml --output-type yaml --age $age_pub --config /dev/null $tmp" > "$yaml_file"
local rc=$?
rm -f "$tmp"
return $rc
}
-29
View File
@@ -1,29 +0,0 @@
pdf-mupdf () {
f=$1
mupdf $f &
while inotifywait -e close_write $f; do
pkill -HUP mupdf;
done
}
pdf-okular () {
f=$1
okular $f 2>&1 > /dev/null &
}
# Open a pdf file with auto refresh
pdf () {
if command -v okular &> /dev/null; then
pdf-okular "$@"
elif command -v mupdf &> /dev/null; then
pdf-mupdf "$@"
else
echo "No pdf reader found"
exit 1
fi
}
# Can't remeber the name
gnome-pdf () {
evince "$@" &
}
-11
View File
@@ -1,11 +0,0 @@
# From https://wiki.archlinux.org/title/rsync
cpr() {
rsync --archive -hh --partial --info=stats1,progress2 --modify-window=1 "$@"
}
mvr() {
rsync --archive -hh --partial --info=stats1,progress2 --modify-window=1 --remove-source-files "$@"
}
sudo-cpr() {
sudo rsync -e "ssh -i $HOME/.ssh/id_ed25519 -F $HOME/.ssh/config" --archive -hh --partial --info=stats1,progress2 --modify-window=1 --remove-source-files "$@"
}
-28
View File
@@ -1,28 +0,0 @@
# Created by newuser for 5.9
ZSHD="$HOME/.zsh.d"
if [[ ! -v ZSH_GRML_SOURCED ]]; then
source $ZSHD/grml-zshrc
fi
source "$ZSHD/rsync.zsh"
source "$ZSHD/misc.zsh"
source "$ZSHD/pdf.zsh"
source "$ZSHD/completion.zsh"
source "$ZSHD/modern-utils.zsh"
source "$ZSHD/develop.zsh"
source "$ZSHD/nix.zsh"
# allow using # at begin
setopt interactivecomments
# give me back the normal `#, ^, ~` !!!
unsetopt extended_glob
# alias
export EDITOR=helix
alias edit=$EDITOR
alias vim=helix
alias dc="docker compose"
export PATH="$HOME/.local/bin:$PATH"