[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: IMG_1387.png (17 KB, 830x490)
17 KB
17 KB PNG
ITT we share scripts/oneliners/functions or any other utils that you use often, they help you and you feel like it could help the others

>inb4 rm -rf /
>any other lame obfusations
>>
alias wcurl = curl -# -O $1 --location --remote-name --remote-time --retry 10 --retry-max-time 10 --continue-at -"
>>
ls -lash
>>
>>108561131
That's actually bretty cool and easy to remember. Thanks, anon.
>>
__fzf_select() {
setopt localoptions pipefail no_aliases 2> /dev/null
local -a tokens
tokens=(${(z)LBUFFER})
local last_word=${tokens[-1]}
local selection
export FZF_CTRL_F_COMMAND=$(
if [[ "$(realpath .)" == "${HOME}" ]] && [[ -n "$last_word" && -e "$last_word" ]]; then
search_path="'$last_word'"
printf '%s' "fd . $search_path --color=always -HiL -d1 -E .histfile -E .git -E .gitignore"
elif [[ "$(realpath .)" == "${HOME}" ]]; then
printf '%s' "fd . --color=always -HiL -d1 -E .histfile -E .git -E .gitignore"
elif [[ -n "$last_word" && -e "$last_word" ]]; then
search_path="'$last_word'"
printf '%s' "fd . $search_path --color=always -HiL -d2 -E .histfile -E .git -E .gitignore"
else
printf '%s' "fd . --color=always -HiL -d2 -E .histfile -E .git -E .gitignore"
fi
)
if [[ -z "$last_word" ]] || [[ ${LBUFFER[-1]} == " " ]]; then
selection=$(eval ${FZF_CTRL_F_COMMAND} | fzf --preview='fzf_preview_wrapper {}')
else
selection=$(eval ${FZF_CTRL_F_COMMAND} | fzf --preview='fzf_preview_wrapper {}' --query "$last_word" | sed "s|$last_word||g")
fi
local ret=$?
return $ret
}

fzf-file-widget() {
__fzf_select
local ret=$?
zle reset-prompt
return $ret
}

if [[ "${FZF_CTRL_F_COMMAND-x}" != "" ]]; then
zle -N fzf-file-widget
bindkey -M vicmd '^F' fzf-file-widget
bindkey -M viins '^F' fzf-file-widget
fi

__fzlf() {
export FZF_CTRL_F_COMMAND=$(
if [[ "$(realpath .)" == "${HOME}" ]]; then
printf '%s' "fd . --color=always -HiL -d1 -E .histfile -E .git -E .gitignore"
else
printf '%s' "fd . --color=always -HiL -d2 -E .histfile -E .git -E .gitignore"
fi
)
FZF_DEFAULT_COMMAND="${FZF_CTRL_F_COMMAND}"
eval ${FZF_DEFAULT_COMMAND} |
fzf -m -d '/' --preview='fzf_preview_wrapper {}'
}

alias -g fzlf=__fzlf
alias -g fff="\
\$(\
fzlf\
)\
"
>>
>>108561245
Well, guys, um.
__fzf_select() {
# all the other shit above this stuff
[[ -n "$selection" ]] && LBUFFER+="$selection"
local ret=$?
return $ret
}

Not sure where this line disappeared to, but it's kind of the most important part of the ctrl-f function. Whoops.
>>
e() { echo >&2 "$@"; "$@"; }
hl() { bat -Ppl "${1:-help}"; }
opts() { "$@" --help |& rg "^\s*-" | hl; }

gits() { : 'gits [DIR] [CMD] [OPTS..] # touch all repos in DIR'
local d=${1:-$HOME/code}; (($#<2)) && set -- _ status --short
find "$d" -maxdepth 2 -type d -name .git | while read -r d
do e git -C "${d%/*}" "${@:2}" || break; echo; done
} # eg: gits . diff --stat # or: gits . push



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.