Add initial files

This commit is contained in:
Santiago Lo Coco 2023-11-22 18:50:55 -03:00
commit 15781c5b01
5 changed files with 215 additions and 0 deletions

2
.open_add Normal file
View File

@ -0,0 +1,2 @@
Finder
System Settings

18
.open_ignore Normal file
View File

@ -0,0 +1,18 @@
grep
Uninstall
Applications
Library
System
Users
Volumes
bin
cores
dev
etc
home
opt
private
sbin
tmp
usr
var

137
capture.zsh Executable file
View File

@ -0,0 +1,137 @@
#!/bin/zsh
#https://github.com/Valodim/zsh-capture-completion
zmodload zsh/zpty || { echo 'error: missing module zsh/zpty' >&2; exit 1 }
# spawn shell
zpty z zsh -f -i
# line buffer for pty output
local line
setopt rcquotes
() {
zpty -w z source $1
repeat 4; do
zpty -r z line
[[ $line == ok* ]] && return
done
echo 'error initializing.' >&2
exit 2
} =( <<< '
# no prompt!
PROMPT=
# load completion system
autoload compinit
compinit -d ~/.zcompdump_capture
# never run a command
bindkey ''^M'' undefined
bindkey ''^J'' undefined
bindkey ''^I'' complete-word
# send a line with null-byte at the end before and after completions are output
null-line () {
echo -E - $''\0''
}
compprefuncs=( null-line )
comppostfuncs=( null-line exit )
# never group stuff!
zstyle '':completion:*'' list-grouped false
# don''t insert tab when attempting completion on empty line
zstyle '':completion:*'' insert-tab false
# no list separator, this saves some stripping later on
zstyle '':completion:*'' list-separator ''''
# we use zparseopts
zmodload zsh/zutil
# override compadd (this our hook)
compadd () {
# check if any of -O, -A or -D are given
if [[ ${@[1,(i)(-|--)]} == *-(O|A|D)\ * ]]; then
# if that is the case, just delegate and leave
builtin compadd "$@"
return $?
fi
# ok, this concerns us!
# echo -E - got this: "$@"
# be careful with namespacing here, we don''t want to mess with stuff that
# should be passed to compadd!
typeset -a __hits __dscr __tmp
# do we have a description parameter?
# note we don''t use zparseopts here because of combined option parameters
# with arguments like -default- confuse it.
if (( $@[(I)-d] )); then # kind of a hack, $+@[(r)-d] doesn''t work because of line noise overload
# next param after -d
__tmp=${@[$[${@[(i)-d]}+1]]}
# description can be given as an array parameter name, or inline () array
if [[ $__tmp == \(* ]]; then
eval "__dscr=$__tmp"
else
__dscr=( "${(@P)__tmp}" )
fi
fi
# capture completions by injecting -A parameter into the compadd call.
# this takes care of matching for us.
builtin compadd -A __hits -D __dscr "$@"
# JESUS CHRIST IT TOOK ME FOREVER TO FIGURE OUT THIS OPTION WAS SET AND WAS MESSING WITH MY SHIT HERE
setopt localoptions norcexpandparam extendedglob
# extract prefixes and suffixes from compadd call. we can''t do zsh''s cool
# -r remove-func magic, but it''s better than nothing.
typeset -A apre hpre hsuf asuf
zparseopts -E P:=apre p:=hpre S:=asuf s:=hsuf
# append / to directories? we are only emulating -f in a half-assed way
# here, but it''s better than nothing.
integer dirsuf=0
# don''t be fooled by -default- >.>
if [[ -z $hsuf && "${${@//-default-/}% -# *}" == *-[[:alnum:]]#f* ]]; then
dirsuf=1
fi
# just drop
[[ -n $__hits ]] || return
# this is the point where we have all matches in $__hits and all
# descriptions in $__dscr!
# display all matches
local dsuf dscr
for i in {1..$#__hits}; do
# add a dir suffix?
(( dirsuf )) && [[ -d $__hits[$i] ]] && dsuf=/ || dsuf=
# description to be displayed afterwards
(( $#__dscr >= $i )) && dscr=" -- ${${__dscr[$i]}##$__hits[$i] #}" || dscr=
echo -E - $IPREFIX$apre$hpre$__hits[$i]$dsuf$hsuf$asuf$dscr
done
}
# signal success!
echo ok')
zpty -w z "$*"$'\t'
integer tog=0
# read from the pty, and parse linewise
while zpty -r z; do :; done | while IFS= read -r line; do
if [[ $line == *$'\0\r' ]]; then
(( tog++ )) && return 0 || continue
fi
# display between toggles
(( tog )) && echo -E - $line
done
return 2

44
launcher.sh Executable file
View File

@ -0,0 +1,44 @@
#!/usr/bin/env bash
cacheDir=${XDG_CACHE_HOME:-"$HOME/.cache"}
cache="$cacheDir/launcher_opts"
historyFile="$cacheDir/launcher_opts_history"
if ! [ -f "$cache" ]; then
/Users/slococo/.local/bin/capture.zsh 'open -a' | sed -e 's/.*-a//' -e "s/\\\//g" -e "s/\r//g" | grep -v -f /Users/slococo/.open_ignore | (cat /Users/slococo/.open_add; cat -) | sort -u > "$cache"
fi
gawk -v histfile=$historyFile '
BEGIN {
while( (getline < histfile) > 0 ) {
sub("^[0-9]+\t","")
print
x[$0]=1
}
} !x[$0]++ ' "$cache" \
| fzf -e --tiebreak=index \
| gawk -v histfile=$historyFile '
BEGIN {
FS=OFS="\t"
while ( (getline < histfile) > 0 ) {
count=$1
sub("^[0-9]+\t","")
fname=$0
history[fname]=count
}
close(histfile)
}
{
history[$0]++
print
}
END {
if(!NR) exit
for (f in history)
print history[f],f | "sort -t '\t' -k1rn >" histfile
}
' \
| xargs -I {} open -a "{}"

14
popup.sh Executable file
View File

@ -0,0 +1,14 @@
#!/usr/bin/env bash
TITLE=mylauncher
SCREEN_WIDTH=`yabai -m query --displays --display | jq .frame.w*2`
SCREEN_HEIGHT=`yabai -m query --displays --display | jq .frame.h*2`
TERM_WIDTH=1280
TERM_HEIGHT=1260
let "X=SCREEN_WIDTH/2-TERM_WIDTH/2"
let "Y=SCREEN_HEIGHT/2-TERM_HEIGHT/2"
alacritty -t "${TITLE}" -o window.position.x="${X}" -o window.position.y="${Y}" -o window.dimensions.lines=35 -o window.dimensions.columns=80 -o window.decorations=none --working-directory "$(pwd)" -e "$1"