Restructuring the repo
This commit is contained in:
parent
21e3cf65e6
commit
3d67598c27
|
@ -1,6 +1,6 @@
|
|||
# crater's script collection
|
||||
|
||||
Some scripts that I wrote over the years and wanted to store with versioning
|
||||
somewhere. Maybe some of them are useful for others.
|
||||
somewhere. Maybe some of them are useful for others, some are probably not.
|
||||
|
||||
Documentation may or may not follow, some scripts include a `--help` output.
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
#!/bin/zsh
|
||||
time=$1; shift
|
||||
echo "DISPLAY=:0.0 sm \"$@\"" | at $time
|
6
bin/idea
6
bin/idea
|
@ -1,6 +0,0 @@
|
|||
#!/bin/zsh
|
||||
unset JAVA_HOME
|
||||
source /etc/profile.d/11_oracle-jdk.sh
|
||||
export IBUS_ENABLE_SYNC_MODE=1
|
||||
export XMODIFIERS=""
|
||||
exec $(ls ${XDG_DATA_HOME:-~/.local/share}/idea-IU-*/bin/idea.sh | sort | tail -n 1)
|
36
bin/venv
36
bin/venv
|
@ -1,36 +0,0 @@
|
|||
#!/bin/zsh
|
||||
|
||||
zparseopts -D -E c=cdhere -cdhere=cdhere h=help -help=help
|
||||
if [[ -n $help ]]; then
|
||||
<<-HELP
|
||||
Usage: ${0:t} [-c] [DIR]
|
||||
|
||||
If DIR contains bin/activate, start a shell with that virtualenv.
|
||||
Otherwise recursively look up virtualenvs in DIR (by looking for dirs ending
|
||||
in "venv") and select one with fzf.
|
||||
|
||||
-c, --cdhere Change back to the current working directory instead of the
|
||||
virtual env's base dir
|
||||
HELP
|
||||
exit
|
||||
fi
|
||||
|
||||
ORIGDIR=$PWD
|
||||
|
||||
venvsh() {
|
||||
cd $1
|
||||
. bin/activate
|
||||
if [[ -n $cdhere ]]; then
|
||||
cd $ORIGDIR
|
||||
fi
|
||||
$SHELL
|
||||
}
|
||||
|
||||
if [[ -n $1 && -e $1/bin/activate ]]; then
|
||||
exec venvsh $1
|
||||
fi
|
||||
|
||||
venv=$(fd -I -t d 'venv$' $1 | fzf)
|
||||
if [[ -n $venv ]]; then
|
||||
venvsh $venv
|
||||
fi
|
49
install.zsh
Executable file
49
install.zsh
Executable file
|
@ -0,0 +1,49 @@
|
|||
#!/bin/zsh
|
||||
|
||||
source ${$(realpath "$0"):h}/lib/common.zsh
|
||||
|
||||
typeset -A interpreter_checked
|
||||
have_interpreter() {
|
||||
if [[ ! $interpreter_checked[$1] ]]; then
|
||||
check "Checking for $1… "
|
||||
if which ruby &> /dev/null; then
|
||||
succeed
|
||||
interpreter_checked[$1]=1
|
||||
return 0
|
||||
else
|
||||
fail "not found in path"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
uses_interpreter() {
|
||||
head -n 1 $2 | grep -q $1
|
||||
}
|
||||
|
||||
if [[ -z $1 ]]; then
|
||||
<<-HELP
|
||||
Usage: $0 [-p PATH] <program_names>
|
||||
HELP
|
||||
exit 1
|
||||
fi
|
||||
|
||||
zparseopts -D -E p:=install_path -path:=install_path f=force -force=force
|
||||
|
||||
if [[ ! $install_path ]]; then
|
||||
install_path=$HOME/.local/bin
|
||||
fi
|
||||
|
||||
for prog in $@; do
|
||||
for lang in zsh ruby python; do
|
||||
if uses_interpreter $lang $prog; then
|
||||
have_interpreter $lang || exit 1
|
||||
fi
|
||||
done
|
||||
if [[ -e $install_path/${prog:t} && ! $force ]]; then
|
||||
error "$prog already exists at $install_path. Skipping."
|
||||
else
|
||||
ln -fsr $prog $install_path
|
||||
fi
|
||||
done
|
41
lib/common.zsh
Normal file
41
lib/common.zsh
Normal file
|
@ -0,0 +1,41 @@
|
|||
autoload -Uz colors && colors
|
||||
|
||||
local c_fail="${fg_bold[red]}✘$reset_color"
|
||||
local c_success="${fg_bold[green]}✔$reset_color"
|
||||
|
||||
check() {
|
||||
echo -n " ? $*"
|
||||
}
|
||||
|
||||
result() {
|
||||
echo -n "\e[s"
|
||||
echo -n "\e[1G $1"
|
||||
echo -n "\e[u"
|
||||
shift
|
||||
echo " $*"
|
||||
}
|
||||
|
||||
fail() { result $c_fail $@ }
|
||||
succeed() { result $c_success $@ }
|
||||
error() { echo -n " "; fail $@ }
|
||||
|
||||
depend() {
|
||||
local missing
|
||||
local i
|
||||
|
||||
for i in "$@"; do
|
||||
type "$i" &>/dev/null || {
|
||||
echo >&2 " $c_fail Missing dependency: $i. Please install it"
|
||||
missing=1
|
||||
}
|
||||
done
|
||||
[[ -n "$missing" ]] && exit 1
|
||||
}
|
||||
|
||||
urlencode() {
|
||||
setopt extendedglob
|
||||
input=$(</dev/stdin)
|
||||
# by jkramer, source: http://stackoverflow.com/a/187853/928769
|
||||
echo "${${(j: :)input}//(#b)(?)/%$[[##16]##${match[1]}]}"
|
||||
}
|
||||
|
6
misc/alert
Executable file
6
misc/alert
Executable file
|
@ -0,0 +1,6 @@
|
|||
#!/bin/zsh
|
||||
time=$1; shift
|
||||
(
|
||||
echo "DISPLAY=$DISPLAY sm \"$@\"" | at $time
|
||||
) &>/dev/null
|
||||
echo "Alerting at $time on screen $DISPLAY"
|
|
@ -1,4 +1,7 @@
|
|||
#!/bin/zsh
|
||||
|
||||
source ${$(realpath "$0"):h:h}/lib/common.zsh
|
||||
|
||||
emulate -L zsh
|
||||
|
||||
SYSTEM_CONFIG_PATH='/etc/dmsearch'
|
||||
|
@ -7,21 +10,6 @@ CACHE_PATH="$HOME/.cache/dmsearch"
|
|||
mkdir -p "${CACHE_PATH}"
|
||||
|
||||
# required software
|
||||
|
||||
depend() {
|
||||
local script="$1"; shift;
|
||||
local missing
|
||||
local i
|
||||
|
||||
for i in "$@"; do
|
||||
type "$i" &>/dev/null || {
|
||||
echo >&2 "$i is required for ${script}. Please install it"
|
||||
missing=1
|
||||
}
|
||||
done
|
||||
[ -n "$missing" ] && exit 1
|
||||
}
|
||||
|
||||
depend dmsearch \
|
||||
rofi \
|
||||
mv \
|
||||
|
@ -33,13 +21,6 @@ depend dmsearch \
|
|||
# helpers
|
||||
################################################################################
|
||||
|
||||
urlencode() {
|
||||
setopt extendedglob
|
||||
input=$(</dev/stdin)
|
||||
# by jkramer, source: http://stackoverflow.com/a/187853/928769
|
||||
echo "${${(j: :)input}//(#b)(?)/%$[[##16]##${match[1]}]}"
|
||||
}
|
||||
|
||||
# define a module option
|
||||
# Parameters:
|
||||
# 1: module id
|
9
misc/findterm
Executable file
9
misc/findterm
Executable file
|
@ -0,0 +1,9 @@
|
|||
#!/bin/zsh
|
||||
for candidate in x-terminal-emulator xdg-terminal alacritty urxvt xterm; do
|
||||
if which $candidate &> /dev/null; then
|
||||
echo $candidate
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
echo "no terminal found" >&2
|
||||
exit 1
|
29
misc/guiterm
Executable file
29
misc/guiterm
Executable file
|
@ -0,0 +1,29 @@
|
|||
#!/bin/zsh
|
||||
|
||||
if [[ "${0:t}" == "guiterm" ]]; then
|
||||
<<-HELP
|
||||
Symlink to g\$progname to start \$progname in tmux in a new terminal or
|
||||
reattach a tmux session named \$progname in a new terminal
|
||||
|
||||
Symlink to g.\$progname to start \$progname in tmux in a new terminal
|
||||
regardless of existing tmux sessions"
|
||||
|
||||
Example symlink names:
|
||||
gmutt: start mutt in a terminal or open the existing one
|
||||
g.zsh: open a terminal running a new zsh session
|
||||
HELP
|
||||
exit 1
|
||||
fi
|
||||
|
||||
prog=${${0:t}[2,-1]}
|
||||
if [[ "$prog[1]" == "." ]]; then
|
||||
prog=${prog[2,-1]}
|
||||
action="tmux new-session ${prog}"
|
||||
elif tmux list-sessions | grep -qe "^${prog}:"; then
|
||||
action="tmux attach -t ${prog}"
|
||||
else
|
||||
action="tmux new-session -s ${prog} ${prog}"
|
||||
fi
|
||||
|
||||
#exec alacritty --title G${prog} -e ${=action}
|
||||
exec alacritty -t G${prog} -e ${=action}
|
21
misc/idea
Executable file
21
misc/idea
Executable file
|
@ -0,0 +1,21 @@
|
|||
#!/bin/zsh
|
||||
unset JAVA_HOME
|
||||
source /etc/profile.d/11_oracle-jdk.sh
|
||||
export IBUS_ENABLE_SYNC_MODE=1
|
||||
export XMODIFIERS=""
|
||||
|
||||
dotfiles=( $HOME/.* )
|
||||
project_dirs=(
|
||||
$HOME/learning
|
||||
$HOME/teaching
|
||||
$HOME/projects
|
||||
$HOME/sandbox
|
||||
$HOME/sources
|
||||
$HOME/toy-projects
|
||||
$HOME/work
|
||||
)
|
||||
|
||||
exec firejail \
|
||||
--whitelist=${^dotfiles} \
|
||||
--whitelist=${^project_dirs} \
|
||||
$(ls ${XDG_DATA_HOME:-~/.local/share}/idea-IU-*/bin/idea.sh | sort | tail -n 1)
|
31
misc/install-proton-ge.zsh
Executable file
31
misc/install-proton-ge.zsh
Executable file
|
@ -0,0 +1,31 @@
|
|||
#!/bin/zsh
|
||||
# installs or updates to latest release of Proton build by GloriousEggroll
|
||||
# saves installed versions in $STEAM_DIR/compatibilitytools.d/proton-ge-tags
|
||||
|
||||
autoload -Uz colors && colors
|
||||
|
||||
if [[ ! -e $HOME/.steam/root/ ]]; then
|
||||
if [[ -e $HOME/.var/app/com.valvesoftware.Steam/data/Steam ]]; then
|
||||
#flatpak-version
|
||||
COMPTOOLSDIR=$HOME/.var/app/com.valvesoftware.Steam/data/Steam/compatibilitytools.d/
|
||||
fi
|
||||
echo "steam root not found"
|
||||
exit 1
|
||||
else
|
||||
COMPTOOLSDIR=$HOME/.steam/root/compatibilitytools.d
|
||||
fi
|
||||
|
||||
mkdir -p $COMPTOOLSDIR
|
||||
|
||||
latest_json=$(curl -s https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases/latest)
|
||||
release_tag=$(jq -r .tag_name <<<$latest_json)
|
||||
|
||||
installed_tags="$COMPTOOLSDIR/proton-ge-tags"
|
||||
|
||||
if grep -q "^$release_tag\$" "$installed_tags"; then
|
||||
echo "${fg_bold[yellow]}Current release $release_tag already installed.$reset_color"
|
||||
else
|
||||
echo $release_tag >> .steam/root/compatibilitytools.d/proton-ge-tags
|
||||
curl -L $(jq -r '.tarball_url'<<<"$latest_json") | tar -C $COMPTOOLSDIR -xvz
|
||||
echo "${fg_bold[green]}Installed release $release_tag.$reset_color"
|
||||
fi
|
3
misc/pathtest
Executable file
3
misc/pathtest
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/zsh
|
||||
|
||||
source ${$(realpath "$0"):h:h}/lib
|
|
@ -27,9 +27,9 @@ fi
|
|||
|
||||
if [[ -e $SCRIPTDIR/$1 ]]; then
|
||||
if [[ -n $dry_run ]]; then
|
||||
$PAGER -F $SCRIPTDIR/$1
|
||||
${PAGER:-less} -F $SCRIPTDIR/$1
|
||||
elif [[ -n $edit ]]; then
|
||||
$EDITOR $SCRIPTDIR/$1
|
||||
${EDITOR:-vim} $SCRIPTDIR/$1
|
||||
else
|
||||
script=$1
|
||||
shift
|
8
misc/share
Executable file
8
misc/share
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!/bin/zsh
|
||||
file_id=$(head -c 12 /dev/urandom|base64| tr '/' '+')
|
||||
file_name=${2:-${1:t}}
|
||||
|
||||
ssh qwerty mkdir -p ~/share/$file_id/
|
||||
rsync -P $1 qwerty:share/$file_id/$file_name
|
||||
ssh qwerty ~/update-www-perms.sh
|
||||
echo https://share.qwertyuiop.de/$file_id/$file_name
|
10
misc/sweechat
Executable file
10
misc/sweechat
Executable file
|
@ -0,0 +1,10 @@
|
|||
#!/bin/zsh
|
||||
if [[ "$1" == "-S" ]]; then
|
||||
shift
|
||||
server=${1};
|
||||
shift
|
||||
else
|
||||
server="qwerty";
|
||||
fi
|
||||
|
||||
exec alacritty -t Weechat -e tmux new-session mosh "${server}" -- tmux attach "$@" -t weechat
|
55
misc/venv
Executable file
55
misc/venv
Executable file
|
@ -0,0 +1,55 @@
|
|||
#!/bin/zsh
|
||||
|
||||
zparseopts -D -E c=cdhere -cdvenv=cdvenv h=help -help=help n=newvenv -new=newvenv t=tmsu -tmsu=tmsu
|
||||
if [[ -n $help ]]; then
|
||||
<<-HELP
|
||||
Usage: ${0:t} [-c] [DIR]
|
||||
${0:t} -t
|
||||
|
||||
If DIR contains bin/activate, start a shell with that virtualenv.
|
||||
Otherwise recursively look up virtualenvs in DIR (by looking for dirs ending
|
||||
in "venv") and select one with fzf.
|
||||
|
||||
-c, --cdvenv Change to the venv directory instead of going back to the
|
||||
current working directory
|
||||
-t, --tmsu list only venvs in a directory with tmsu tag lang=python
|
||||
HELP
|
||||
exit
|
||||
fi
|
||||
|
||||
ORIGDIR=$PWD
|
||||
|
||||
venvsh() {
|
||||
cd $1
|
||||
. bin/activate
|
||||
if [[ -z $cdvenv ]]; then
|
||||
cd $ORIGDIR
|
||||
fi
|
||||
$SHELL
|
||||
}
|
||||
|
||||
if [[ -n $tmsu ]]; then
|
||||
venv=$(
|
||||
for i in $(tmsu files --directory lang=python); do
|
||||
[[ -d $i/venv ]] && echo $i/venv
|
||||
done | fzf)
|
||||
if [[ -n $venv ]]; then
|
||||
exec venvsh $venv
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n $newvenv ]]; then
|
||||
python -mvenv ${1:-venv}
|
||||
exec venvsh ${1:-venv}
|
||||
fi
|
||||
|
||||
if [[ -n $1 && -e $1/bin/activate ]]; then
|
||||
exec venvsh $1
|
||||
fi
|
||||
|
||||
venv=$(fd -I -t d 'venv$' $1 | fzf)
|
||||
if [[ -n $venv ]]; then
|
||||
exec venvsh $venv
|
||||
fi
|
|
@ -1,10 +1,12 @@
|
|||
#!/bin/zsh
|
||||
|
||||
source ${$(realpath "$0"):h:h}/lib/common.zsh
|
||||
|
||||
profile="${0:t}"
|
||||
|
||||
need firefox
|
||||
need firejail
|
||||
depend firefox firejail
|
||||
|
||||
mkdir -p $HOME/.jails/firefox-$profile
|
||||
|
||||
exec firejail --private=$HOME/.jails/firefox-$profile \
|
||||
firefox --no-remote "$@"
|
||||
firefox --class $profile --no-remote "$@"
|
|
@ -3,8 +3,8 @@
|
|||
# install this program with the name xc and symlink it as xs.
|
||||
# xc will use the clipboard selection, while xs while use the primary selection
|
||||
|
||||
source $(which need)
|
||||
need xclip
|
||||
source ${$(realpath "$0"):h:h}/lib/common.zsh
|
||||
depend xclip
|
||||
|
||||
function get_primary() { xclip -o -selection primary }
|
||||
function get_clipboard() { xclip -o -selection clipboard }
|
||||
|
@ -19,7 +19,7 @@ function show_both() {
|
|||
}
|
||||
|
||||
function read_both() {
|
||||
need pee moreutils
|
||||
depend pee
|
||||
pee "xclip -i -selection primary" "xclip -i -selection clipboard"
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ function common() {
|
|||
"showboth") show_both ;;
|
||||
"sed") $getc | sed -e "$@" | $setc; $getc;;
|
||||
"pipe") $getc | "$@" | $setc; $getc;;
|
||||
"edit") need vipe moreutils; $getc | vipe | $setc; $getc;;
|
||||
"edit") depend vipe; $getc | vipe | $setc; $getc;;
|
||||
"") if [[ -t 0 ]]; then $getc; else $setc; fi;;
|
||||
*) <<-HELP
|
||||
Usage: xc [COMMAND]
|
2
misc/zenity-askpass
Executable file
2
misc/zenity-askpass
Executable file
|
@ -0,0 +1,2 @@
|
|||
#!/bin/zsh
|
||||
zenity --password --title="sudo password prompt" --timeout=10
|
66
void/xbps-worldfile
Executable file
66
void/xbps-worldfile
Executable file
|
@ -0,0 +1,66 @@
|
|||
#!/bin/zsh
|
||||
|
||||
zparseopts -D -E h=help -help=help d=desc -describe=desc
|
||||
|
||||
function not-in-left() {
|
||||
awk 'NR==FNR{a[$0]=1;next}!a[$0]' "$@"
|
||||
}
|
||||
|
||||
function first-col() {
|
||||
cut -d$'\t' -f1
|
||||
}
|
||||
|
||||
function info() {
|
||||
printf "$@" >&2
|
||||
}
|
||||
|
||||
if [[ -n $help ]]; then
|
||||
echo 'Usage: xbps-worldfile [-d]'
|
||||
echo 'Edit a list of manually installed packages in your editor and update the pkgdb'
|
||||
echo
|
||||
echo ' -d, --describe Query short description for packages and display it in the list (slow)'
|
||||
exit
|
||||
fi
|
||||
|
||||
TMPFILE=$(mktemp -p ${TMPDIR:-/tmp} xbps-worldfile.XXXXXXXXXX)
|
||||
|
||||
if [[ -n $desc ]]; then
|
||||
info "Generating worldfile with descriptions\n"
|
||||
xbps-query -m | while read pkg; do
|
||||
info .
|
||||
printf "%-40s\t%s\n" $pkg "$(xbps-query -p short_desc $pkg)"
|
||||
done > $TMPFILE
|
||||
else
|
||||
xbps-query -m > $TMPFILE
|
||||
fi
|
||||
|
||||
EDITFILE=$(mktemp -p ${TMPDIR:-/tmp} xbps-worldfile.edit.XXXXXXXXXX)
|
||||
cp $TMPFILE $EDITFILE
|
||||
|
||||
$EDITOR $EDITFILE
|
||||
|
||||
autopkgs=$(not-in-left $EDITFILE $TMPFILE | first-col)
|
||||
manualpkgs=$(not-in-left $TMPFILE $EDITFILE | first-col)
|
||||
rm $TMPFILE $EDITFILE
|
||||
|
||||
if [[ -z $manualpkgs && -z $autopkgs ]]; then
|
||||
info "No changes.\n"
|
||||
exit
|
||||
fi
|
||||
info "\e[92minstalling:\e[0m\n${manualpkgs}\n\n"
|
||||
info "\e[93mchanging to auto:\e[0m\n${autopkgs}\n\n"
|
||||
|
||||
|
||||
info "\e[1mContinue? [y/n]:"
|
||||
if ! read -q; then exit; fi
|
||||
|
||||
if [[ -n $manualpkgs ]]; then
|
||||
xbps-install $=manualpkgs
|
||||
xbps-pkgdb -m manual $=manualpkgs
|
||||
fi
|
||||
|
||||
if [[ -n $autopkgs ]]; then
|
||||
xbps-pkgdb -m auto $=autopkgs
|
||||
info "\e[93mcleaning orphans\e[0m"
|
||||
xbps-remove -Ro
|
||||
fi
|
23
void/xrevdep
Executable file
23
void/xrevdep
Executable file
|
@ -0,0 +1,23 @@
|
|||
#!/bin/zsh
|
||||
|
||||
CLEAR="\e[2K\e[${COLUMNS}D"
|
||||
printc() {
|
||||
printf "$CLEAR\e[32m%s\e[0m" "$*" >&2
|
||||
}
|
||||
|
||||
revdep() {
|
||||
printc "> $1"
|
||||
parents=$(xbps-query -X "$1")
|
||||
|
||||
if [[ -z $parents ]]; then
|
||||
echo $1
|
||||
else
|
||||
while IFS= read -r i; do
|
||||
revdep $i
|
||||
done <<<"$parents"
|
||||
fi
|
||||
}
|
||||
|
||||
result=$(revdep "$1")
|
||||
printc
|
||||
sort -u <<<"$result"
|
Loading…
Reference in a new issue