Skip to content

Instantly share code, notes, and snippets.

@zorchp
Last active December 23, 2025 05:58
Show Gist options
  • Select an option

  • Save zorchp/5e6938e0f0c9180fc00c5ddd2a2f9a10 to your computer and use it in GitHub Desktop.

Select an option

Save zorchp/5e6938e0f0c9180fc00c5ddd2a2f9a10 to your computer and use it in GitHub Desktop.
xx ()
{
if [[ -z "$1" ]]; then
echo "Usage: $0 <filename.cpp|filename.cc>";
return 1;
fi;
local src_file=$1;
local file_ext="${src_file##*.}";
local dest_file="${src_file%.*}.out";
local CXX_bin=/opt/compiler/gcc-12/bin/g++;
if [[ "$file_ext" != "cpp" && "$file_ext" != "cc" && "$file_ext" != "cxx" ]]; then
echo "Error: Unsupported file type '$file_ext'. Supported: .cpp, .cc, .cxx";
return 1;
fi;
shift 1;
${CXX_bin} "$@" -g -O2 -std=c++23 -lpthread "$src_file" -o "$dest_file" && ./"${dest_file}"
}
scppath() {
local target="$1"
if [ -z "$target" ]; then
target="."
fi
local abs_path
abs_path=$(readlink -f "$target") || return
echo "$(whoami)@$(hostname):$abs_path" | tee >(copy)
}
copy() {
# 如果是交互式终端(没有重定向输入),提示用法
if [ -t 0 ]; then
echo "Usage: cat file | copy_clipboard"
return 1
fi
local content
content=$(cat)
# base64 编码,适配 Linux/macOS
local encoded
if base64 --help 2>&1 | grep -q -- "-w"; then
encoded=$(echo -n "$content" | base64 -w 0) # Linux
else
encoded=$(echo -n "$content" | base64) # macOS 无 -w
fi
# 发送 OSC 52 复制命令
echo -ne "\e]52;c;${encoded}\a"
}
alias vimdiff='vimdiff -c "windo set wrap" '
#vimdiff() {
# vim -d +"windo set wrap" "$*"
#}
cmd() {
if (($# != 1)); then
echo "get cmdline by pid"
echo "Usage: $0 <pid>"
return 1
fi
echo $(cat /proc/$1/cmdline | tr '\0' ' ')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment