-rw-r--r-- functions.zsh
1 # 2 # misc functions 3 # 4 5 # use last browsed directory automatically with ranger 6 if which ranger &> /dev/null; then 7 _ranger=`which ranger` 8 ranger-cd() { 9 tempfile="$(mktemp -t ranger.XXXXXX)" 10 if [[ -f $HOME/.local/bin/ranger ]] 11 then 12 $HOME/.local/bin/ranger --choosedir="$tempfile" "${@:-$(pwd)}" 13 else 14 $_ranger --choosedir="$tempfile" "${@:-$(pwd)}" 15 fi 16 test -f "$tempfile" && 17 if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then 18 cd -- "$(cat "$tempfile")" 19 fi 20 rm -f -- "$tempfile" 21 } 22 ranger() { # prevent nested ranger instances when shelling from ranger 23 if [ -z "$RANGER_LEVEL" ]; then 24 ranger-cd "$@" 25 else 26 exit 27 fi 28 } 29 fi 30 31 function y() { 32 local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd 33 command yazi "$@" --cwd-file="$tmp" 34 IFS= read -r -d '' cwd < "$tmp" 35 [ "$cwd" != "$PWD" ] && [ -d "$cwd" ] && builtin cd -- "$cwd" 36 rm -f -- "$tmp" 37 } 38 39 shebang() { # create new file, add shebang, and vim 40 touch $1 41 chmod +x $1 42 echo -e "#!/usr/bin/env bash\n" > $1 43 nvim +2 $1 44 } 45 shebangpy() { # create new file, add shebang, and vim 46 touch $1 47 chmod +x $1 48 echo -e "#!/usr/bin/env python3\n" > $1 49 nvim +2 $1 50 } 51 52 # copy file path to clipboard 53 cpath() { readlink -f $1 | copy } 54 55 56 57 sb () { 58 sed 's/.*/\L&/g; s/\(.\{1\}\)\(.\)/\1\U\2/g' <<< "$@" 59 } 60 61 62 hex_fg() { 63 #eval printf \"x1b[38\;2\;$(printf "\$((16#%s));\$((16#%s));\$((16#%s))\n" $(echo ${1//#} | fold -w2))m\" # <- works up to leading escape 64 eval printf \\\\\"x1b[38\;2\;$(printf "\$((16#%s));\$((16#%s));\$((16#%s))\n" $(echo ${1//#} | fold -w2))m\" 65 } 66 67 hex_bg() { 68 #eval printf \"x1b[38\;2\;$(printf "\$((16#%s));\$((16#%s));\$((16#%s))\n" $(echo ${1//#} | fold -w2))m\" # <- works up to leading escape 69 eval printf \\\\\"x1b[48\;2\;$(printf "\$\(\(16#%s\)\);\$\(\(16#%s\)\);\$\(\(16#%s\)\)\n" $(echo ${1//#} | fold -w2))m\" 70 } 71 72 avi_to_mp4() { 73 ffmpeg -i $1 -c:v libx264 -preset slow -crf 19 -c:a libvo_aacenc -b:a 128k $2 74 } 75 76 rec_screen() { 77 if [[ -n "$WAYLAND_DISPLAY" ]] 78 then 79 wf-recorder 80 else 81 ffmpeg -f x11grab -r 30 -s 1920x1080 -i $DISPLAY -pix_fmt yuv420p out.mp4 82 fi 83 } 84 rec_screen_mic() { 85 ffmpeg -f x11grab -r 30 -s 1920x1080 -i $DISPLAY -f pulse -ac 2 -i default out.mkv 86 } 87 88 #go() { 89 # title="$@" 90 # if [[ -z "$title" ]] 91 # then 92 # echo "usage: go <title>" 93 # return 94 # fi 95 # alacritty msg create-window --title "$title" --working-directory ~/git --command /opt/homebrew/bin/tmux 96 #} 97