summaryrefslogtreecommitdiff
path: root/home/xyz/.local/bin/gitmetap
blob: c058986024ba3eac97b41a513b1d2eb882e9c0b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/sh
# GIT META Print

# -rw-r--r-- == binary 110100100 == octal 644
# https://stackoverflow.com/a/1796009
$1 ls-tree -r --name-only --full-tree HEAD | dirnameall | awk -v a="$2/" '{printf("%s%s\n",a,$0)}' | tr '\n' '\0' | xargs -0 ls -ldA -- | awk '{
	k=0
	for(i=0;i<=8;i++)
		k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i))
	if(k) {
		for(i=10;$i && $i!="->";i++)
			$9=$9" "$i
		printf("%0o %s %s %s\n",k,$3,$4,$9)
	}
}' > "$3"

#$1 ls-tree -r --name-only --full-tree HEAD | awk -v a="$2/" '{printf("%s%s\n",a,$0)}' | tr '\n' '\0' | xargs -0 ls -ldA -- | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k){for(i=10;$i && $i!="->";i++)$9=$9" "$i;printf("%0o %s %s %s\n",k,$3,$4,$9)}}' > "$3"
# but other situation seems less use -F as default? # steal from sdcv arch wiki # CALCURSE_PAGER less can't use -F, else ? and > hotkey will only blink the text # -x4 to use 4 spaces instead of default 8. Even if I specify `tabs 4` in .bashrc, this is still needed for less. export LESS=-FRXix4 export MANPAGER='nvim +Man!' # This MANSECT prioritize POSIX manpages. After use it for a long time, I think it is not suitable for me any more. #export MANSECT='1p:1:n:l:8:3p:3:0p:0:2:5:4:9:6:7' #export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket" export INPUTRC="$XDG_CONFIG_HOME/.inputrc" # Thanks to https://github.com/trialuser02/qt6gtk2/pull/5 # enable color for `tree` command, not forced export CLICOLOR=1 # for pacdiff, without using aur neovim-drop-in or neovim-symlinks export DIFFPROG='nvim -d' export MAKEFLAGS="-j$(nproc --all)" # use sudo find for some files or dirs that has no permission ex: ~/.cache/paru/clone/ #export FZF_DEFAULT_COMMAND="fd --no-ignore --hidden --exclude .git" #export FZF_CTRL_T_COMMAND="fd --absolute-path --no-ignore --hidden --exclude .git" #export FZF_ALT_C_COMMAND="fd --no-ignore --hidden --type d --exclude .git" export FZF_DEFAULT_COMMAND="find . -mindepth 1 -path '*/\.git' -prune -o -print" # https://askubuntu.com/questions/444551/get-absolute-path-of-files-using-find-command # following two lines if use "" on the outermost, will not perfom expected, not sure why # use "$(pwd -P)" instead of "$PWD", else it will not work in symlink dir # -P to make it show realpath, another way is: "$(realpath .)", but I prefer pwd because it is shell builtin which maybe faster # or I can use find -L or -H (not sure about differences between the two), but I prefer realpath instead of symlink export FZF_CTRL_T_COMMAND='find "$(pwd -P)" -mindepth 1 -path "*/\.git" -prune -o -print' #export FZF_CTRL_T_COMMAND='sudo find "$(pwd)" -path "*/\.git" -prune -o -print' # ~+ is bashism #export FZF_CTRL_T_COMMAND="sudo find ~+ -path '*/\.git' -prune -o -print" export FZF_ALT_C_COMMAND="find . -mindepth 1 -path '*/\.git' -prune -o -type d -print" # must source .bashrc after export _ZO_ECHO=1 and INPUTRC=..., else these two env will has no effect, don't know why # here `. ~/.bashrc` same as `source ~/.bashrc`, see `source filename` in `man bash`, and `. file` in `man dash` # `. file` is POSIX compliant, while `source file` is not # https://github.com/koalaman/shellcheck/wiki/SC3046 #[[ -f ~/.bashrc ]] && . ~/.bashrc [ -f "$HOME/.bashrc" ] && . "$HOME/.bashrc"