diff options
Diffstat (limited to 'dotfiles/.local')
48 files changed, 1424 insertions, 0 deletions
diff --git a/dotfiles/.local/bin/activenv b/dotfiles/.local/bin/activenv new file mode 100755 index 0000000..6ffac10 --- /dev/null +++ b/dotfiles/.local/bin/activenv @@ -0,0 +1,3 @@ +#!/bin/bash + +source ~/Documents/venvs/$1/bin/activate diff --git a/dotfiles/.local/bin/camtoggle b/dotfiles/.local/bin/camtoggle new file mode 100755 index 0000000..ba8b0d3 --- /dev/null +++ b/dotfiles/.local/bin/camtoggle @@ -0,0 +1,3 @@ +#!/bin/sh + +pkill -f /dev/video || mpv --gpu-context=wayland --no-osc --no-input-default-bindings --input-conf=/dev/null --geometry=-0-0 --autofit=30% --title="mpvfloat" /dev/video2 diff --git a/dotfiles/.local/bin/changeoutput b/dotfiles/.local/bin/changeoutput new file mode 100755 index 0000000..eab2cf9 --- /dev/null +++ b/dotfiles/.local/bin/changeoutput @@ -0,0 +1,18 @@ +#!/bin/sh + +if [ -z "$1" ]; then + echo "Usage: $0 <sinkId/sinkName>" >&2 + echo "Valid sinks:" >&2 + pactl list short sinks >&2 + exit 1 +fi + +newSink="$1" + +pactl list short sink-inputs|while read stream; do + streamId=$(echo $stream|cut '-d ' -f1) + echo "moving stream $streamId" + pactl move-sink-input "$streamId" "$newSink" +done + +pactl set-default-sink $newSink diff --git a/dotfiles/.local/bin/ddquakemite b/dotfiles/.local/bin/ddquakemite new file mode 100755 index 0000000..ef67955 --- /dev/null +++ b/dotfiles/.local/bin/ddquakemite @@ -0,0 +1,16 @@ +#!/bin/bash + +if ! [ -z "$(swaymsg -t get_tree | grep 'quakemite')" ]; then + if [ -z "$(swaymsg -t get_tree | grep -A 42 'quakemite' | tail -n 1 | grep 'true')" ]; then + swaymsg '[title="quakemite"] scratchpad show' + else + swaymsg '[title="quakemite"] move scratchpad' + fi +else + $TERMINAL -t "quakemite" -e "$SHELL -c 'TERM=xterm-256color; TERMINAL=termite; tmux a || tmux'" & + sleep 0.2s + currenty=$(swaygetcurrentwindow | cut -d ' ' -f1 | cut -d ',' -f2 ) + let moveup=$currenty-25 + swaymsg move up "$moveup px" +fi + diff --git a/dotfiles/.local/bin/ddtelegram b/dotfiles/.local/bin/ddtelegram new file mode 100755 index 0000000..8ddff22 --- /dev/null +++ b/dotfiles/.local/bin/ddtelegram @@ -0,0 +1,12 @@ +#!/bin/sh + +if pidof telegram-desktop > /dev/null; then + if [ -z $(swaymsg -t get_tree | grep -A 1 'telegramdesktop' | tail -n 1 | grep 'true') ]; then + swaymsg '[app_id="telegramdesktop"] scratchpad show' + else + swaymsg '[app_id="telegramdesktop"] move scratchpad' + fi +else + telegram-desktop +fi + diff --git a/dotfiles/.local/bin/ddvk b/dotfiles/.local/bin/ddvk new file mode 100755 index 0000000..dedd2c9 --- /dev/null +++ b/dotfiles/.local/bin/ddvk @@ -0,0 +1,12 @@ +#!/bin/sh + +if pidof vk > /dev/null; then + if [ -z $(swaymsg -t get_tree | grep -B 5 'vk' | head -n 1 | grep 'true') ]; then + swaymsg '[instance="vk"] scratchpad show' + else + swaymsg '[instance="vk"] move scratchpad' + fi +else + xway vk-messenger +fi + diff --git a/dotfiles/.local/bin/doccompiler b/dotfiles/.local/bin/doccompiler new file mode 100755 index 0000000..b95d7a3 --- /dev/null +++ b/dotfiles/.local/bin/doccompiler @@ -0,0 +1,34 @@ +#!/bin/sh + +# Script to compile some documents to their final output (.tex, .md, .rmd, etc.) +# Taken from one of Luke Smith's scripts, except this one focuses solely on +# document compilation and doesn't compile any scripts or programs. + +file=$(readlink -f "$1") +dir=$(dirname "$file") +base="${file%.*}" + +cd "$dir" || exit + +textype() { \ + command="pdflatex -interaction=nonstopmode" + ( sed 5q "$file" | grep -i -q 'xelatex' ) && command="xelatex" + $command --output-directory="$dir" "$base" && + grep -i addbibresource "$file" >/dev/null && + biber --input-directory "$dir" "$base" && + $command --output-directory="$dir" "$base" && + $command --output-directory="$dir" "$base" + } + +case "$file" in + *\.ms) refer -PS -e "$file" | groff -me -ms -kept -T pdf > "$base".pdf ;; + *\.mom) refer -PS -e "$file" | groff -mom -kept -T pdf > "$base".pdf ;; + *\.[0-9]) refer -PS -e "$file" | groff -mandoc -T pdf > "$base".pdf ;; + *\.rmd) echo "require(rmarkdown); rmarkdown::render('$file', quiet=TRUE)" | R -q --vanilla ;; + *\.tex) textype "$file" ;; + *\.md) pandoc "$file" --pdf-engine=xelatex -o "$base".pdf ;; + *\.sent) setsid sent "$file" 2>/dev/null & ;; + *) echo "Couldn't figure out file type!" && exit 1 ;; +esac + +echo "Compiled successfully" diff --git a/dotfiles/.local/bin/git-prompt b/dotfiles/.local/bin/git-prompt new file mode 100755 index 0000000..048d2d7 --- /dev/null +++ b/dotfiles/.local/bin/git-prompt @@ -0,0 +1,484 @@ +# bash/zsh git prompt support +# +# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org> +# Distributed under the GNU General Public License, version 2.0. +# +# This script allows you to see repository status in your prompt. +# +# To enable: +# +# 1) Copy this file to somewhere (e.g. ~/.git-prompt.sh). +# 2) Add the following line to your .bashrc/.zshrc: +# source ~/.git-prompt.sh +# 3a) Change your PS1 to call __git_ps1 as +# command-substitution: +# Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ ' +# ZSH: setopt PROMPT_SUBST ; PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ ' +# the optional argument will be used as format string. +# 3b) Alternatively, for a slightly faster prompt, __git_ps1 can +# be used for PROMPT_COMMAND in Bash or for precmd() in Zsh +# with two parameters, <pre> and <post>, which are strings +# you would put in $PS1 before and after the status string +# generated by the git-prompt machinery. e.g. +# Bash: PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "' +# will show username, at-sign, host, colon, cwd, then +# various status string, followed by dollar and SP, as +# your prompt. +# ZSH: precmd () { __git_ps1 "%n" ":%~$ " "|%s" } +# will show username, pipe, then various status string, +# followed by colon, cwd, dollar and SP, as your prompt. +# Optionally, you can supply a third argument with a printf +# format string to finetune the output of the branch status +# +# The repository status will be displayed only if you are currently in a +# git repository. The %s token is the placeholder for the shown status. +# +# The prompt status always includes the current branch name. +# +# In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty value, +# unstaged (*) and staged (+) changes will be shown next to the branch +# name. You can configure this per-repository with the +# bash.showDirtyState variable, which defaults to true once +# GIT_PS1_SHOWDIRTYSTATE is enabled. +# +# You can also see if currently something is stashed, by setting +# GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed, +# then a '$' will be shown next to the branch name. +# +# If you would like to see if there're untracked files, then you can set +# GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're untracked +# files, then a '%' will be shown next to the branch name. You can +# configure this per-repository with the bash.showUntrackedFiles +# variable, which defaults to true once GIT_PS1_SHOWUNTRACKEDFILES is +# enabled. +# +# If you would like to see the difference between HEAD and its upstream, +# set GIT_PS1_SHOWUPSTREAM="auto". A "<" indicates you are behind, ">" +# indicates you are ahead, "<>" indicates you have diverged and "=" +# indicates that there is no difference. You can further control +# behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated list +# of values: +# +# verbose show number of commits ahead/behind (+/-) upstream +# name if verbose, then also show the upstream abbrev name +# legacy don't use the '--count' option available in recent +# versions of git-rev-list +# git always compare HEAD to @{upstream} +# svn always compare HEAD to your SVN upstream +# +# By default, __git_ps1 will compare HEAD to your SVN upstream if it can +# find one, or @{upstream} otherwise. Once you have set +# GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by +# setting the bash.showUpstream config variable. +# +# If you would like to see more information about the identity of +# commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE +# to one of these values: +# +# contains relative to newer annotated tag (v1.6.3.2~35) +# branch relative to newer tag or branch (master~4) +# describe relative to older annotated tag (v1.6.3.1-13-gdd42c2f) +# default exactly matching tag +# +# If you would like a colored hint about the current dirty state, set +# GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on +# the colored output of "git status -sb" and are available only when +# using __git_ps1 for PROMPT_COMMAND or precmd. + +# check whether printf supports -v +__git_printf_supports_v= +printf -v __git_printf_supports_v -- '%s' yes >/dev/null 2>&1 + +# stores the divergence from upstream in $p +# used by GIT_PS1_SHOWUPSTREAM +__git_ps1_show_upstream () +{ + local key value + local svn_remote svn_url_pattern count n + local upstream=git legacy="" verbose="" name="" + + svn_remote=() + # get some config options from git-config + local output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')" + while read -r key value; do + case "$key" in + bash.showupstream) + GIT_PS1_SHOWUPSTREAM="$value" + if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then + p="" + return + fi + ;; + svn-remote.*.url) + svn_remote[$((${#svn_remote[@]} + 1))]="$value" + svn_url_pattern="$svn_url_pattern\\|$value" + upstream=svn+git # default upstream is SVN if available, else git + ;; + esac + done <<< "$output" + + # parse configuration values + for option in ${GIT_PS1_SHOWUPSTREAM}; do + case "$option" in + git|svn) upstream="$option" ;; + verbose) verbose=1 ;; + legacy) legacy=1 ;; + name) name=1 ;; + esac + done + + # Find our upstream + case "$upstream" in + git) upstream="@{upstream}" ;; + svn*) + # get the upstream from the "git-svn-id: ..." in a commit message + # (git-svn uses essentially the same procedure internally) + local -a svn_upstream + svn_upstream=($(git log --first-parent -1 \ + --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null)) + if [[ 0 -ne ${#svn_upstream[@]} ]]; then + svn_upstream=${svn_upstream[${#svn_upstream[@]} - 2]} + svn_upstream=${svn_upstream%@*} + local n_stop="${#svn_remote[@]}" + for ((n=1; n <= n_stop; n++)); do + svn_upstream=${svn_upstream#${svn_remote[$n]}} + done + + if [[ -z "$svn_upstream" ]]; then + # default branch name for checkouts with no layout: + upstream=${GIT_SVN_ID:-git-svn} + else + upstream=${svn_upstream#/} + fi + elif [[ "svn+git" = "$upstream" ]]; then + upstream="@{upstream}" + fi + ;; + esac + + # Find how many commits we are ahead/behind our upstream + if [[ -z "$legacy" ]]; then + count="$(git rev-list --count --left-right \ + "$upstream"...HEAD 2>/dev/null)" + else + # produce equivalent output to --count for older versions of git + local commits + if commits="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)" + then + local commit behind=0 ahead=0 + for commit in $commits + do + case "$commit" in + "<"*) ((behind++)) ;; + *) ((ahead++)) ;; + esac + done + count="$behind $ahead" + else + count="" + fi + fi + + # calculate the result + if [[ -z "$verbose" ]]; then + case "$count" in + "") # no upstream + p="" ;; + "0 0") # equal to upstream + p="=" ;; + "0 "*) # ahead of upstream + p=">" ;; + *" 0") # behind upstream + p="<" ;; + *) # diverged from upstream + p="<>" ;; + esac + else + case "$count" in + "") # no upstream + p="" ;; + "0 0") # equal to upstream + p=" u=" ;; + "0 "*) # ahead of upstream + p=" u+${count#0 }" ;; + *" 0") # behind upstream + p=" u-${count% 0}" ;; + *) # diverged from upstream + p=" u+${count#* }-${count% *}" ;; + esac + if [[ -n "$count" && -n "$name" ]]; then + __git_ps1_upstream_name=$(git rev-parse \ + --abbrev-ref "$upstream" 2>/dev/null) + if [ $pcmode = yes ]; then + # see the comments around the + # __git_ps1_branch_name variable below + p="$p \${__git_ps1_upstream_name}" + else + p="$p ${__git_ps1_upstream_name}" + # not needed anymore; keep user's + # environment clean + unset __git_ps1_upstream_name + fi + fi + fi + +} + +# Helper function that is meant to be called from __git_ps1. It +# injects color codes into the appropriate gitstring variables used +# to build a gitstring. +__git_ps1_colorize_gitstring () +{ + if [[ -n ${ZSH_VERSION-} ]]; then + local c_red='%F{red}' + local c_green='%F{green}' + local c_lblue='%F{blue}' + local c_clear='%f' + else + # Using \[ and \] around colors is necessary to prevent + # issues with command line editing/browsing/completion! + local c_red='\[\e[31m\]' + local c_green='\[\e[32m\]' + local c_lblue='\[\e[1;34m\]' + local c_clear='\[\e[0m\]' + fi + local bad_color=$c_red + local ok_color=$c_green + local flags_color="$c_lblue" + + local branch_color="" + if [ $detached = no ]; then + branch_color="$ok_color" + else + branch_color="$bad_color" + fi + c="$branch_color$c" + + z="$c_clear$z" + if [ "$w" = "*" ]; then + w="$bad_color$w" + fi + if [ -n "$i" ]; then + i="$ok_color$i" + fi + if [ -n "$s" ]; then + s="$flags_color$s" + fi + if [ -n "$u" ]; then + u="$bad_color$u" + fi + r="$c_clear$r" +} + +# __git_ps1 accepts 0 or 1 arguments (i.e., format string) +# when called from PS1 using command substitution +# in this mode it prints text to add to bash PS1 prompt (includes branch name) +# +# __git_ps1 requires 2 or 3 arguments when called from PROMPT_COMMAND (pc) +# in that case it _sets_ PS1. The arguments are parts of a PS1 string. +# when two arguments are given, the first is prepended and the second appended +# to the state string when assigned to PS1. +# The optional third parameter will be used as printf format string to further +# customize the output of the git-status string. +# In this mode you can request colored hints using GIT_PS1_SHOWCOLORHINTS=true +__git_ps1 () +{ + local pcmode=no + local detached=no + local ps1pc_start='\u@\h:\w ' + local ps1pc_end='\$ ' + local printf_format=' %s ' + + case "$#" in + 2|3) pcmode=yes + ps1pc_start="$1" + ps1pc_end="$2" + printf_format="${3:-$printf_format}" + ;; + 0|1) printf_format="${1:-$printf_format}" + ;; + *) return + ;; + esac + + local repo_info rev_parse_exit_code + repo_info="$(git rev-parse --git-dir --is-inside-git-dir \ + --is-bare-repository --is-inside-work-tree \ + --short HEAD 2>/dev/null)" + rev_parse_exit_code="$?" + + if [ -z "$repo_info" ]; then + if [ $pcmode = yes ]; then + #In PC mode PS1 always needs to be set + PS1="$ps1pc_start$ps1pc_end" + fi + return + fi + + local short_sha + if [ "$rev_parse_exit_code" = "0" ]; then + short_sha="${repo_info##*$'\n'}" + repo_info="${repo_info%$'\n'*}" + fi + local inside_worktree="${repo_info##*$'\n'}" + repo_info="${repo_info%$'\n'*}" + local bare_repo="${repo_info##*$'\n'}" + repo_info="${repo_info%$'\n'*}" + local inside_gitdir="${repo_info##*$'\n'}" + local g="${repo_info%$'\n'*}" + + local r="" + local b="" + local step="" + local total="" + if [ -d "$g/rebase-merge" ]; then + read b 2>/dev/null <"$g/rebase-merge/head-name" + read step 2>/dev/null <"$g/rebase-merge/msgnum" + read total 2>/dev/null <"$g/rebase-merge/end" + if [ -f "$g/rebase-merge/interactive" ]; then + r="|REBASE-i" + else + r="|REBASE-m" + fi + else + if [ -d "$g/rebase-apply" ]; then + read step 2>/dev/null <"$g/rebase-apply/next" + read total 2>/dev/null <"$g/rebase-apply/last" + if [ -f "$g/rebase-apply/rebasing" ]; then + read b 2>/dev/null <"$g/rebase-apply/head-name" + r="|REBASE" + elif [ -f "$g/rebase-apply/applying" ]; then + r="|AM" + else + r="|AM/REBASE" + fi + elif [ -f "$g/MERGE_HEAD" ]; then + r="|MERGING" + elif [ -f "$g/CHERRY_PICK_HEAD" ]; then + r="|CHERRY-PICKING" + elif [ -f "$g/REVERT_HEAD" ]; then + r="|REVERTING" + elif [ -f "$g/BISECT_LOG" ]; then + r="|BISECTING" + fi + + if [ -n "$b" ]; then + : + elif [ -h "$g/HEAD" ]; then + # symlink symbolic ref + b="$(git symbolic-ref HEAD 2>/dev/null)" + else + local head="" + if ! read head 2>/dev/null <"$g/HEAD"; then + if [ $pcmode = yes ]; then + PS1="$ps1pc_start$ps1pc_end" + fi + return + fi + # is it a symbolic ref? + b="${head#ref: }" + if [ "$head" = "$b" ]; then + detached=yes + b="$( + case "${GIT_PS1_DESCRIBE_STYLE-}" in + (contains) + git describe --contains HEAD ;; + (branch) + git describe --contains --all HEAD ;; + (describe) + git describe HEAD ;; + (* | default) + git describe --tags --exact-match HEAD ;; + esac 2>/dev/null)" || + + b="$short_sha..." + b="($b)" + fi + fi + fi + + if [ -n "$step" ] && [ -n "$total" ]; then + r="$r $step/$total" + fi + + local w="" + local i="" + local s="" + local u="" + local c="" + local p="" + + if [ "true" = "$inside_gitdir" ]; then + if [ "true" = "$bare_repo" ]; then + c="BARE:" + else + b="GIT_DIR!" + fi + elif [ "true" = "$inside_worktree" ]; then + if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] && + [ "$(git config --bool bash.showDirtyState)" != "false" ] + then + git diff --no-ext-diff --quiet --exit-code || w="*" + if [ -n "$short_sha" ]; then + git diff-index --cached --quiet HEAD -- || i="+" + else + i="#" + fi + fi + if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ] && + [ -r "$g/refs/stash" ]; then + s="$" + fi + + if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] && + [ "$(git config --bool bash.showUntrackedFiles)" != "false" ] && + git ls-files --others --exclude-standard --error-unmatch -- '*' >/dev/null 2>/dev/null + then + u="%${ZSH_VERSION+%}" + fi + + if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then + __git_ps1_show_upstream + fi + fi + + local z="${GIT_PS1_STATESEPARATOR-" "}" + + # NO color option unless in PROMPT_COMMAND mode + if [ $pcmode = yes ] && [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then + __git_ps1_colorize_gitstring + fi + + b=${b##refs/heads/} + if [ $pcmode = yes ]; then + # In pcmode (and only pcmode) the contents of + # $gitstring are subject to expansion by the shell. + # Avoid putting the raw ref name in the prompt to + # protect the user from arbitrary code execution via + # specially crafted ref names (e.g., a ref named + # '$(IFS=_;cmd=sudo_rm_-rf_/;$cmd)' would execute + # 'sudo rm -rf /' when the prompt is drawn). Instead, + # put the ref name in a new global variable (in the + # __git_ps1_* namespace to avoid colliding with the + # user's environment) and reference that variable from + # PS1. + __git_ps1_branch_name=$b + # note that the $ is escaped -- the variable will be + # expanded later (when it's time to draw the prompt) + b="\${__git_ps1_branch_name}" + fi + + local f="$w$i$s$u" + local gitstring="$c$b${f:+$z$f}$r$p" + + if [ $pcmode = yes ]; then + if [ "${__git_printf_supports_v-}" != yes ]; then + gitstring=$(printf -- "$printf_format" "$gitstring") + else + printf -v gitstring -- "$printf_format" "$gitstring" + fi + PS1="$ps1pc_start$gitstring$ps1pc_end" + else + printf -- "$printf_format" "$gitstring" + fi +} diff --git a/dotfiles/.local/bin/i3barbattery b/dotfiles/.local/bin/i3barbattery new file mode 100755 index 0000000..edc89c3 --- /dev/null +++ b/dotfiles/.local/bin/i3barbattery @@ -0,0 +1,34 @@ +#!/bin/sh +# Taken from Luke Smith's rice +# Takes battery name as an argument (e.g. BAT0) + +case $BLOCK_BUTTON in + 3) notify-send "🔋 Battery module" "🔋: discharging +🛑: not charging +♻: stagnant charge +🔌: charging +⚡: charged +❗: battery very low! +- Text color reflects charge left" ;; +esac + +capacity=$(cat /sys/class/power_supply/"$1"/capacity) || exit +status=$(cat /sys/class/power_supply/"$1"/status) + +if [ "$capacity" -ge 75 ]; then + color="#689d6a" +elif [ "$capacity" -ge 50 ]; then + color="#ffffff" +elif [ "$capacity" -ge 25 ]; then + color="#ffff00" +else + color="#ff0000" + warn="❗" +fi + +[ -z $warn ] && warn=" " + +[ "$status" = "Charging" ] && color="#ffffff" + +printf "<span color='%s'>%s%s%s</span>" "$color" "$(echo "$status" | sed -e "s/,//;s/Discharging/🔋/;s/Not Charging/🛑/;s/Charging/🔌/;s/Unknown/♻️/;s/Full/⚡/;s/ 0*/ /g;s/ :/ /g")" "$warn" "$(echo "$capacity" | sed -e 's/$/%/')" + diff --git a/dotfiles/.local/bin/i3barmusic b/dotfiles/.local/bin/i3barmusic new file mode 100755 index 0000000..5647a81 --- /dev/null +++ b/dotfiles/.local/bin/i3barmusic @@ -0,0 +1,18 @@ +#!/bin/sh + +filter() { + sed "/^volume:/d" | tac | sed -e "s/\\&/&/g;s/\\[paused\\].*/<span color=\"gray\" font_style=\"italic\">/g;s/\\[playing\\].*/<span>/g" | tr -d '\n' | sed -e "s/$/<\\/span>/g" + } + +case $BLOCK_BUTTON in + 1) mpc toggle | filter ;; + 2) mpc status | filter && setsid "$TERMINAL" -e ncmpcpp & ;; + 3) mpc status | filter && notify-send "🎵 Music module" "\- Shows mpd song playing. +- Italic when paused. +- Left click opens ncmpcpp. +- Middle click pauses. +- Scroll changes track.";; # right click, pause/unpause + 4) mpc prev | filter ;; # scroll up, previous + 5) mpc next | filter ;; # scroll down, next + *) mpc status | filter ;; +esac; exit diff --git a/dotfiles/.local/bin/i3barrecstatus b/dotfiles/.local/bin/i3barrecstatus new file mode 100755 index 0000000..5c8160a --- /dev/null +++ b/dotfiles/.local/bin/i3barrecstatus @@ -0,0 +1,8 @@ +#!/bin/sh + +if [ -f "$HOME/.recordingpid" ]; then + printf "rec ⏺" + exit +fi + +printf "" diff --git a/dotfiles/.local/bin/i3barweather b/dotfiles/.local/bin/i3barweather new file mode 100755 index 0000000..0ae6d3c --- /dev/null +++ b/dotfiles/.local/bin/i3barweather @@ -0,0 +1,18 @@ +#!/bin/bash + +location="Saint Petersburg" + +if [[ "$location" != "" ]] +then + location="~${location// /+}" +fi + +forecast=$(curl -s wttr.in/$location?format=1) + +if [[ ${#forecast} -gt 30 ]] +then + exit +fi + +echo $forecast + diff --git a/dotfiles/.local/bin/linkhandler b/dotfiles/.local/bin/linkhandler new file mode 100755 index 0000000..c616d04 --- /dev/null +++ b/dotfiles/.local/bin/linkhandler @@ -0,0 +1,22 @@ +#!/bin/sh + +# Feed script a url or file location. +# If an image, it will view in sxiv, +# if a video or gif, it will view in mpv +# if a music file or pdf, it will download, +# otherwise it opens link in browser. + +# If no url given. Opens browser. For using script as $BROWSER. +[ -z "$1" ] && { "$BROWSER"; exit; } + +case "$1" in + *mkv|*webm|*mp4|*youtube.com*|*youtu.be*|*hooktube.com*|*bitchute.com*) + setsid mpv --input-ipc-server=/tmp/mpvsoc$(date +%s) -quiet "$1" >/dev/null 2>&1 & ;; + *png|*jpg|*jpe|*jpeg|*gif) + curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///")" && sxiv -a "/tmp/$(echo "$1" | sed "s/.*\///")" >/dev/null 2>&1 & ;; + *mp3|*flac|*opus|*mp3?source*) + setsid tsp curl -LO "$1" >/dev/null 2>&1 & ;; + *) + if [ -f "$1" ]; then "$TERMINAL" -e "$EDITOR $1" + else setsid "$BROWSER" "$1" >/dev/null 2>&1 & fi ;; +esac diff --git a/dotfiles/.local/bin/listsinks b/dotfiles/.local/bin/listsinks new file mode 100755 index 0000000..d76e3e2 --- /dev/null +++ b/dotfiles/.local/bin/listsinks @@ -0,0 +1,3 @@ +#!/bin/sh + +pactl list short sinks | awk '{ print $2 }' diff --git a/dotfiles/.local/bin/lmc b/dotfiles/.local/bin/lmc new file mode 100755 index 0000000..c740c0c --- /dev/null +++ b/dotfiles/.local/bin/lmc @@ -0,0 +1,17 @@ +#!/bin/sh + +case "$1" in + "up") pamixer --allow-boost -i "$2" || amixer sset Master 2%+ ;; + "down") pamixer --allow-boost -d "$2" || amixer sset Master 2%- ;; + "mute") pamixer --allow-boost -t || amixer sset Master toggle ;; + "truemute") pamixer --allow-boost -m || amixer sset Master mute ;; + "toggle") mpc toggle ; $newmpd ;; + "pause") mpc pause ; $newmpd ;; + "forward") mpc seek +"$2" ; $newmpd ;; + "back") mpc seek -"$2" ; $newmpd ;; + "next") mpc next ; $newmpd ;; + "prev") mpc prev ; $newmpd ;; + "replay") mpc seek 0% ; $newmpd ;; +esac + +exit diff --git a/dotfiles/.local/bin/lock-color b/dotfiles/.local/bin/lock-color new file mode 100755 index 0000000..445d779 --- /dev/null +++ b/dotfiles/.local/bin/lock-color @@ -0,0 +1,86 @@ +#!/bin/sh + +#B='#00000000' # blank +#C='#ffffff22' # clear ish +#D='#b58900ff' # default +#T='#fcbd00dd' # text +#W='#880000bb' # wrong +#V='#fcbd00dd' # verifying + +B='#00000000' # blank +C='#ffffff22' # clear ish +D='#ffffffff' # default +T='#dac99dff' # text +W='#880000bb' # wrong +V='#023982dd' # verifying +# Approximate timeout rate in milliseconds (checked every 5 seconds). +timeout="30000" + + +if [ "$(ps cax | grep sway)" ]; then + swaylock & + + swayidle timeout 15 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"' & + + while [ "$(pgrep -x swaylock)" ] + do + sleep 1 + done + + pkill -n swayidle + exit +fi +# Take a screenshot: +#scrot /tmp/screen.png + +#cp ~/.config/wall.png /tmp/screen.png +# Create a blur on the shot: +#convert /tmp/screen.png -paint 1 -swirl 360 /tmp/screen.png +#convert /tmp/screen.png -brightness-contrast -20,-20 -paint 1 -noise 0x8 -blur 9,9 /tmp/screen.png + +i3lock \ + --layoutcolor=$T \ + --timecolor=$T \ + --datecolor=$T \ + --verifcolor=$T \ + --wrongcolor=$W \ + --keyhlcolor=$V \ + --insidecolor=$B \ + --ringcolor=$T \ + --linecolor=$B \ + --separatorcolor=$D \ + --insidecolor=$B \ + --insidewrongcolor=$B \ + --insidevercolor=$B \ + --color=#000000 \ + --clock \ + --radius=150 \ + --ring-width=5 \ + --timestr="%H:%M:%S" \ + --datestr="%A %e, %b %Y" \ + --veriftext="Verifying..." \ + --wrongtext="Nope!" \ + --noinputtext="BLANK" \ + --time-font=furacodenerdfontmono \ + --date-font=ibmplexsans \ + --timesize=45 \ + --datesize=24 \ + +# If still locked after $timeout milliseconds, turn off screen. +while [ "$(pgrep -x i3lock)" ] +do + if [ $timeout -lt $(xssstate -i) ] + then + xset dpms force off + fi + sleep 1 +done + +# --blur 7 \ +# --keylayout 2 \ +# --textsize=20 +# --modsize=10 +# --timefont=comic-sans +# --datefont=monofur +# etc + diff --git a/dotfiles/.local/bin/mailcheck b/dotfiles/.local/bin/mailcheck new file mode 100755 index 0000000..bf49de9 --- /dev/null +++ b/dotfiles/.local/bin/mailcheck @@ -0,0 +1,35 @@ +#!/bin/sh +# Sync mail and give notification if there is new mail. + +# Run only if user logged in (prevent cron errors) +w | grep "^$USER\W" >/dev/null || exit + +# Checks for internet connection and set notification script. +ping -q -c 1 1.1.1.1 > /dev/null || exit +command -v notify-send >/dev/null || echo "Note that \`libnotify\` or \`libnotify-send\` should be installed for pop-up mail notifications with this script." + +export DISPLAY=:0.0 + +notify() { + notify-send "📬 Email" "$2 new mail(s) in \`$1\` account." + mplayer $HOME/.soundalerts/mail.mp3 +} + +# Run mbsync. You can feed this script different settings. +if [ $# -eq 0 ]; then + mbsync -a +else + mbsync "$@" +fi + +# Check all accounts/mailboxes for new mail. Notify if there is new content. +for account in "$HOME/.local/share/mail/"* +do + acc="$(echo "$account" | sed "s/.*\///")" + newcount=$(find "$HOME/.local/share/mail/$acc/INBOX/new/" "$HOME/.local/share/mail/$acc/Inbox/new/" "$HOME/.local/share/mail/$acc/inbox/new/" -type f -newer "$HOME/.config/mutt/.mailsynclastrun" 2> /dev/null | wc -l) + [ "$newcount" -gt "0" ] && notify "$acc" "$newcount" & +done +notmuch new 2>/dev/null + +#Create a touch file that indicates the time of the last run of mailsync +touch "$HOME/.config/mutt/.mailsynclastrun" diff --git a/dotfiles/.local/bin/mako_launch b/dotfiles/.local/bin/mako_launch new file mode 100755 index 0000000..4b61208 --- /dev/null +++ b/dotfiles/.local/bin/mako_launch @@ -0,0 +1,9 @@ +#!/bin/sh + +# Terminate already running mako instance +killall -q mako + +# Wait until the processes have been shut down +while pgrep -u $UID -x mako >/dev/null; do sleep 1; done + +mako --background-color "#2d333ff3" --border-color "#434c5e" --text-color "#e5e9f0" --font="BlexMono Nerd Font Mono 10" --default-timeout 5000 --height 300 diff --git a/dotfiles/.local/bin/menublk b/dotfiles/.local/bin/menublk new file mode 100755 index 0000000..0ca0607 --- /dev/null +++ b/dotfiles/.local/bin/menublk @@ -0,0 +1,106 @@ +#!/bin/bash + +# Script for mounting/unmounting drives (including encrypted ones) +# For encrypted drives, it works only if there's just one partition inside the +# crypt_LUKS volume + +# Yaroslav de la Peña Smirnov + +. $HOME/.bemenurc + +readarray -t blkdevs <<< "$(lsblk -r -o NAME,TYPE,FSTYPE,MOUNTPOINT | tail -n +2)" + +get_mountable() { + for blkdev in "${blkdevs[@]}"; do + name="$(cut -d " " -f1 <<< "${blkdev}")" + btype="$(cut -d " " -f2 <<< "${blkdev}")" + fstype="$(cut -d " " -f3 <<< "${blkdev}")" + mountpoint="$(cut -d " " -f4 <<< "${blkdev}")" + if [ "$btype" = "part" ]; then + if [ -z "$mountpoint" ]; then + if [ "$fstype" = "crypto_LUKS" ]; then + if [ "$(lsblk -r -o FSTYPE "/dev/$name" | tail -n 1)" = "crypto_LUKS" ]; then + echo "$name" + fi + else + echo "$name" + fi + fi + fi + done +} + +get_unmountable() { + for blkdev in "${blkdevs[@]}"; do + name="$(cut -d " " -f1 <<< "${blkdev}")" + btype="$(cut -d " " -f2 <<< "${blkdev}")" + fstype="$(cut -d " " -f3 <<< "${blkdev}")" + mountpoint="$(cut -d " " -f4 <<< "${blkdev}")" + if [ "$btype" = "part" ]; then + if [ -z "$mountpoint" ] && [ "$fstype" = "crypto_LUKS" ]; then + mountpoint="$(lsblk -r -o MOUNTPOINT "/dev/$name" | tail -n 1)" + fi + if [ -n "$mountpoint" ] && [ "$mountpoint" != "/" ] && [ "$mountpoint" != "/boot" ]; then + echo "$name" + fi + fi + done +} + +mount_dev() { + fstype="$(lsblk -r -o FSTYPE "/dev/$1" | tail -n 1)" + part="/dev/$1" + if [ "$fstype" = "crypto_LUKS" ]; then + password="$(bemenu -p "Enter passphrase for encrypted drive:" --tf="$BEMENU_TF" --tb="$BEMENU_NB" --ff="$BEMENU_NB" --fb="$BEMENU_NB" --fn="$BEMENU_FN" --nb="$BEMENU_NB" --nf="$BEMENU_NF" --hf="$BEMENU_HF" --hb="$BEMENU_HB")" + if [ -z "$password" ]; then + exit 0 + fi + printf "%s" "$password" > "$HOME/.cache/diskey" + part="$(udisksctl unlock --key-file="$HOME/.cache/diskey" -b "/dev/$1" | cut -d " " -f4 )" + part="${part%?}" + rm -f "$HOME/.cache/diskey" + fi + message="$(udisksctl mount -b "$part")" + if [ $? -eq 0 ]; then + notify-send "💽Drive mounting" "$message" + else + notify-send "💽Drive mounting" "An error occurred, could not mount device $1" + fi +} + +unmount_dev() { + fstype="$(lsblk -r -o FSTYPE "/dev/$1" | sed "2q;d")" + if [ "$fstype" = "crypto_LUKS" ]; then + volume="/dev/mapper/$(lsblk -r -o NAME "/dev/$1" | tail -n 1)" + if udisksctl unmount -b "$volume" && udisksctl lock -b "/dev/$1"; then + notify-send "💽Drive manager" "Device $1 has been unmounted and locked" + else + notify-send "💽Drive manager" "An error occurred, could not unmount device $1" + fi + else + if udisksctl unmount -b "/dev/$1"; then + notify-send "💽Drive manager" "Device $1 has been unmounted" + else + notify-send "💽Drive manager" "An error occurred, could not unmount device $1" + fi + fi +} + +action="$(printf "mount\nunmount\n" | bemenu -p "What to do?" --tf="$BEMENU_TF" --tb="$BEMENU_NB" --fb="$BEMENU_NB" --fn="$BEMENU_FN" --nb="$BEMENU_NB" --nf="$BEMENU_NF" --hf="$BEMENU_HF" --hb="$BEMENU_HB")" + +case "$action" in + mount) + blkdev="$(get_mountable | bemenu -p "Choose device to mount:" --tf="$BEMENU_TF" --tb="$BEMENU_NB" --fb="$BEMENU_NB" --fn="$BEMENU_FN" --nb="$BEMENU_NB" --nf="$BEMENU_NF" --hf="$BEMENU_HF" --hb="$BEMENU_HB")" + if [ -z "$blkdev" ]; then + exit 0 + fi + mount_dev "$blkdev";; + unmount) + blkdev="$(get_unmountable | bemenu -p "Choose device to umount:" --tf="$BEMENU_TF" --tb="$BEMENU_NB" --fb="$BEMENU_NB" --fn="$BEMENU_FN" --nb="$BEMENU_NB" --nf="$BEMENU_NF" --hf="$BEMENU_HF" --hb="$BEMENU_HB")" + if [ -z "$blkdev" ]; then + exit 0 + fi + unmount_dev "$blkdev";; + *) + notify-send "💽Drive manager" "That's not an option";; +esac diff --git a/dotfiles/.local/bin/menudisplay b/dotfiles/.local/bin/menudisplay new file mode 100755 index 0000000..6064bff --- /dev/null +++ b/dotfiles/.local/bin/menudisplay @@ -0,0 +1,14 @@ +#!/bin/sh + +# Source settings from .bemenurc +. $HOME/.bemenurc + +display=$(swaymsg -t get_outputs | grep -E "name" | sed "s/^.*\"name\": \"//g;s/\",$//g;" | bemenu -p "Select output: " --tf="$BEMENU_TF" --tb="$BEMENU_NB" --fb="$BEMENU_NB" --fn="$BEMENU_FN" --nb="$BEMENU_NB" --nf="$BEMENU_NF" --hf="$BEMENU_HF" --hb="$BEMENU_HB") + +if [ -z $display ]; then + exit 0 +fi + +action=$(printf "enable\ndisable\n" | bemenu -p "Choose action: " --tf="$BEMENU_TF" --tb="$BEMENU_NB" --fb="$BEMENU_NB" --fn="$BEMENU_FN" --nb="$BEMENU_NB" --nf="$BEMENU_NF" --hf="$BEMENU_HF" --hb="$BEMENU_HB") + +swaymsg output $display $action diff --git a/dotfiles/.local/bin/menuducksearch b/dotfiles/.local/bin/menuducksearch new file mode 100755 index 0000000..979c365 --- /dev/null +++ b/dotfiles/.local/bin/menuducksearch @@ -0,0 +1,16 @@ +#!/bin/sh + +# Gives a dmenu prompt to search DuckDuckGo. +# Without input, will open DuckDuckGo.com. +# Anything else, it search it. + +# Source settings from .bemenurc +. $HOME/.bemenurc + +choice=$(echo "" | bemenu -i -p "Search DuckDuckGo:" --tf="$BEMENU_TF" --tb="$BEMENU_NB" --fb="$BEMENU_NB" --fn="$BEMENU_FN" --nb="$BEMENU_NB" --nf="$BEMENU_NF" --hf="$BEMENU_HF" --hb="$BEMENU_HB") || exit 1 + +if [ "$choice" = "" ]; then + $BROWSER "https://duckduckgo.com" +else + $BROWSER "https://duckduckgo.com/?q=$choice&t=ffab&atb=v1-1" +fi diff --git a/dotfiles/.local/bin/menuemoji b/dotfiles/.local/bin/menuemoji new file mode 100755 index 0000000..8f0720c --- /dev/null +++ b/dotfiles/.local/bin/menuemoji @@ -0,0 +1,16 @@ +#!/bin/sh +# Give dmenu list of all unicode characters to copy. +# Shows the selected character in dunst if running. + +# Source settings from .bemenurc +. $HOME/.bemenurc + +chosen=$(grep -v "#" ~/.emoji | bemenu -i -l 25 --tf="$BEMENU_TF" --tb="$BEMENU_NB" --fb="$BEMENU_NB" --fn="$BEMENU_FN" --nb="$BEMENU_NB" --nf="$BEMENU_NF" --hf="$BEMENU_HF" --hb="$BEMENU_HB") + +if [ -z $chosen ]; then + exit 0 +fi + +c=$(echo "$chosen" | sed "s/ .*//") +echo "$c" | tr -d '\n' | wl-copy +notify-send "'$c' copied to clipboard." diff --git a/dotfiles/.local/bin/menugrim b/dotfiles/.local/bin/menugrim new file mode 100755 index 0000000..bc77c11 --- /dev/null +++ b/dotfiles/.local/bin/menugrim @@ -0,0 +1,33 @@ +#!/bin/sh + +if ! [ -d $SCROT_DIR ]; then + mkdir -p $SCROT_DIR +fi + +# Source settings from .bemenurc +. $HOME/.bemenurc + +notify_saved() { + notify-send "screenshot has been saved in $SCROT_DIR" ; +} + +notify_copied() { + notify-send "screenshot has been copied to clipboard" ; +} + +case "$1" in + --quick|-q) + grim $SCROT_DIR/fullscreen-"$(date '+%y%m%d-%H%M-%S').png"; notify_saved ;; + *) + case "$(printf "a selected area\ncurrent window\nfull screen\na selected area (copy)\ncurrent window (copy)\nfull screen (copy)\n" | bemenu -l 6 -i -p "Screenshot which area?" --tf="$BEMENU_TF" --tb="$BEMENU_NB" --fb="$BEMENU_NB" --fn="$BEMENU_FN" --nb="$BEMENU_NB" --nf="$BEMENU_NF" --hf="$BEMENU_HF" --hb="$BEMENU_HB")" in + "a selected area") grim -g "$(slurp)" $SCROT_DIR/selected-"$(date '+%y%m%d-%H%M-%S').png"; notify_saved ;; + "current window") grim -g "$(swaygetcurrentwindow)" $SCROT_DIR/window-"$(date '+%y%m%d-%H%M-%S').png"; notify_saved ;; + "full screen") grim $SCROT_DIR/fullscreen-"$(date '+%y%m%d-%H%M-%S').png"; notify_saved ;; + "a selected area (copy)") grim -g "$(slurp)" - | wl-copy; notify_copied ;; + "current window (copy)") grim -g "$(swaygetcurrentwindow)" - | wl-copy; notify_copied ;; + "full screen (copy)") grim - | wl-copy; notify_copied ;; + *) exit 0 ;; + esac +esac + + diff --git a/dotfiles/.local/bin/menumako b/dotfiles/.local/bin/menumako new file mode 100755 index 0000000..6589c32 --- /dev/null +++ b/dotfiles/.local/bin/menumako @@ -0,0 +1,6 @@ +#!/bin/sh + +# Source settings from .bemenurc +. $HOME/.bemenurc + +makoctl menu bemenu '-p "What to do?" --tf="$BEMENU_TF" --tb="$BEMENU_NB" --fb="$BEMENU_NB" --fn="$BEMENU_FN" --nb="$BEMENU_NB" --nf="$BEMENU_NF" --hf="$BEMENU_HF" --hb="$BEMENU_HB"' diff --git a/dotfiles/.local/bin/menuoutput b/dotfiles/.local/bin/menuoutput new file mode 100755 index 0000000..5e29f66 --- /dev/null +++ b/dotfiles/.local/bin/menuoutput @@ -0,0 +1,13 @@ +#!/bin/sh +# Change audio output for all streams and set as default using dmenu + +# Source settings from .bemenurc +. $HOME/.bemenurc + +output=$(listsinks | bemenu -p "Select audio output: " --tf="$BEMENU_TF" --tb="$BEMENU_NB" --fb="$BEMENU_NB" --fn="$BEMENU_FN" --nb="$BEMENU_NB" --nf="$BEMENU_NF" --hf="$BEMENU_HF" --hb="$BEMENU_HB") + +[ "$output" != "" ] || exit + +changeoutput $output + +notify-send "🔉 Audio output switched" "Audio output switched to '$output'" diff --git a/dotfiles/.local/bin/menuprompt b/dotfiles/.local/bin/menuprompt new file mode 100755 index 0000000..c336679 --- /dev/null +++ b/dotfiles/.local/bin/menuprompt @@ -0,0 +1,7 @@ +#!/bin/sh +# A dmenu binary prompt script. +# Gives a dmenu prompt labeled with $1 to perform command $2. +# For example: +# `./prompt "Do you want to shutdown?" "shutdown -h now"` + +[ "$(printf "No\\nYes" | bemenu -i -p "$1" --tf="$BEMENU_TF" --tb="$BEMENU_NB" --fb="$BEMENU_NB" --fn="$BEMENU_FN" --nb="$BEMENU_NB" --nf="$BEMENU_NF" --hf="$BEMENU_HF" --hb="$BEMENU_HB")" = "Yes" ] && $2 diff --git a/dotfiles/.local/bin/menurun b/dotfiles/.local/bin/menurun new file mode 100755 index 0000000..530cac7 --- /dev/null +++ b/dotfiles/.local/bin/menurun @@ -0,0 +1,8 @@ +#!/bin/sh + +# Source settings from .bemenurc +. $HOME/.bemenurc + +action=$(compgen -c | sort -u | bemenu -p "Run:" --tf="$BEMENU_TF" --tb="$BEMENU_NB" --fb="$BEMENU_NB" --fn="$BEMENU_FN" --nb="$BEMENU_NB" --nf="$BEMENU_NF" --hf="$BEMENU_HF" --hb="$BEMENU_HB") +$action + diff --git a/dotfiles/.local/bin/menusession b/dotfiles/.local/bin/menusession new file mode 100755 index 0000000..3867b73 --- /dev/null +++ b/dotfiles/.local/bin/menusession @@ -0,0 +1,8 @@ +#!/bin/sh + +# Source settings from .bemenurc +. $HOME/.bemenurc + +action=$(printf "logout\nsuspend\nreboot\npoweroff\n" | bemenu -p "What to do?" --tf="$BEMENU_TF" --tb="$BEMENU_NB" --fb="$BEMENU_NB" --fn="$BEMENU_FN" --nb="$BEMENU_NB" --nf="$BEMENU_NF" --hf="$BEMENU_HF" --hb="$BEMENU_HB") + +swaysession $action diff --git a/dotfiles/.local/bin/menuxrun b/dotfiles/.local/bin/menuxrun new file mode 100755 index 0000000..7ce556e --- /dev/null +++ b/dotfiles/.local/bin/menuxrun @@ -0,0 +1,7 @@ +#!/bin/sh + +# Source settings from .bemenurc +. $HOME/.bemenurc + +action=$(compgen -c | sort -u | bemenu -p "Force run inside XWayland:" --tf="$BEMENU_TF" --tb="$BEMENU_NB" --fb="$BEMENU_NB" --fn="$BEMENU_FN" --nb="$BEMENU_NB" --nf="$BEMENU_NF" --hf="$BEMENU_HF" --hb="$BEMENU_HB") +xway $action diff --git a/dotfiles/.local/bin/mopidy_launch b/dotfiles/.local/bin/mopidy_launch new file mode 100755 index 0000000..d6bd4cf --- /dev/null +++ b/dotfiles/.local/bin/mopidy_launch @@ -0,0 +1,4 @@ +#!/bin/sh + +killall -q mopidy +mopidy diff --git a/dotfiles/.local/bin/notistats b/dotfiles/.local/bin/notistats new file mode 100755 index 0000000..0da5b7b --- /dev/null +++ b/dotfiles/.local/bin/notistats @@ -0,0 +1,10 @@ +#!/bin/sh + +body=$(echo -e "Screen brightness:\t$(xbacklight -get)"; +lscpu | grep 'CPU MHz'; +sensors | grep 'Package id 0' | sed 's/Package id 0/CPU temp/' | awk '{print $1 $2 "\t" $3}'; +sensors | grep 'fan'; +echo print\(\'BAT0 drainage:\\t{}W\'.format\($(grep 'POWER_SUPPLY_POWER_NOW' /sys/class/power_supply/BAT0/uevent | awk -F '=' '{print $2}')/1000000\)\) | python; +echo print\(\'BAT1 drainage:\\t{}W\'.format\($(grep 'POWER_SUPPLY_POWER_NOW' /sys/class/power_supply/BAT1/uevent | awk -F '=' '{print $2}')/1000000\)\) | python) + +notify-send "Hardware status" "$body" diff --git a/dotfiles/.local/bin/paccheck b/dotfiles/.local/bin/paccheck new file mode 100755 index 0000000..1284134 --- /dev/null +++ b/dotfiles/.local/bin/paccheck @@ -0,0 +1,10 @@ +#!/bin/sh + +ping -q -c 1 1.1.1.1 > /dev/null || exit + +notify-send "⬆ Update check" "Checking for updates..." + +sudo pacman -Sy +upno=$(pacman -Qu | wc -l) + +notify-send "⬆ Update Check" "$upno updates are available" diff --git a/dotfiles/.local/bin/qmi_setup b/dotfiles/.local/bin/qmi_setup new file mode 100755 index 0000000..62fcc82 --- /dev/null +++ b/dotfiles/.local/bin/qmi_setup @@ -0,0 +1,104 @@ +#!/bin/bash + +### +# This script automate the setup of QMI supported wwan devices. +# +# Tested on following environment: +# * Lenovo ThinkPad X220 (4286-CTO) +# * Gentoo/Linux, Linux Kernel 3.9.6 +# * NTT Docomo UIM card (Xi LTE SIM) +# * Sierra Wireless, Inc. Gobi 3000 wireless wan module +# (FRU 60Y3257, vendor and device id is 1199:9013) +# memo: +# I recommend to check if your wwan module works fine +# for your mobile broadband provider with Windows +# especially if you imported the device from other country. +# You may have to initialize your device for your region. +# * Required kernel config (other modules may be also required): +# - qmi_wwan (CONFIG_USB_NET_QMI_WWAN) +# - qcserial (CONFIG_USB_SERIAL_QUALCOMM) +# * Required settings: +# - you may have to create /etc/qmi-network.conf. +# My qmi-network.conf has only a line "APN=mopera.net". +# + +# your wwan device name created by qmi_wwan kernel module +# check it with "ip a" or "ifconfig -a". it may be wwan0? +WWAN_DEV=wwp0s20f0u6 +# your cdc_wdm modem location +CDC_WDM=/dev/cdc-wdm0 +# this script uses following qmi commands +QMICLI=/usr/bin/qmicli +QMI_NETWORK=/usr/bin/qmi-network +# the places of following commands vary depending on your distribution +IFCONFIG=/usr/bin/ifconfig +DHCPCD=/usr/bin/dhcpcd +SUDO=/usr/bin/sudo + +function helpmsg { + echo "usage: $0 {start|stop|restart|status}" + exit 1 +} + +function qmi_start { + $COMMAND_PREFIX $IFCONFIG $WWAN_DEV up + $COMMAND_PREFIX $QMICLI -d $CDC_WDM --dms-set-operating-mode=online + if [ $? -ne 0 ]; then + echo "your wwan device may be RFKilled?" + exit 1 + fi + $COMMAND_PREFIX $QMI_NETWORK $CDC_WDM start + $COMMAND_PREFIX $DHCPCD $WWAN_DEV +} + +function qmi_stop { + $COMMAND_PREFIX $QMI_NETWORK $CDC_WDM stop + $COMMAND_PREFIX kill `cat /var/run/dhcpcd-${WWAN_DEV}.pid` + $COMMAND_PREFIX $IFCONFIG $WWAN_DEV down +} + +function qmi_strength { + dbm=`$COMMAND_PREFIX $QMICLI -d $CDC_WDM --nas-get-signal-strength | tr "'" " " | grep Network | head -1 | awk '{print $4}'` + echo -n "Signal strength is " + if [ $dbm -ge -73 ]; then + echo -n 'Excellent' + elif [ $dbm -ge -83 ]; then + echo -n 'Good' + elif [ $dbm -ge -93 ]; then + echo -n 'OK' + elif [ $dbm -ge -109 ]; then + echo -n 'Marginal' + else + echo Unknown + fi + echo " (${dbm} dBm)" +} + +function qmi_status { + $COMMAND_PREFIX $QMI_NETWORK $CDC_WDM status + qmi_strength +} + +# check argument number +if [ $# -ne 1 ] +then + helpmsg +fi + +# check permission +if [ `whoami` != 'root' ] +then + echo "warning: root permission required. setting command prefix to 'sudo'." + COMMAND_PREFIX=$SUDO +fi + +# run commands +case $1 in + start) qmi_start ;; + stop) qmi_stop ;; + restart) qmi_stop; qmi_start ;; + status) qmi_status ;; + *) helpmsg ;; +esac + + diff --git a/dotfiles/.local/bin/setbg b/dotfiles/.local/bin/setbg new file mode 100755 index 0000000..29a11d7 --- /dev/null +++ b/dotfiles/.local/bin/setbg @@ -0,0 +1,3 @@ +#!/bin/sh + +swaymsg output "*" background ~/.config/wall1.png fill diff --git a/dotfiles/.local/bin/setbglblur b/dotfiles/.local/bin/setbglblur new file mode 100755 index 0000000..8a3d51b --- /dev/null +++ b/dotfiles/.local/bin/setbglblur @@ -0,0 +1,8 @@ +#!/bin/sh + +vertical=$(swaymsg -t get_outputs | jq ".[0].current_mode.height") +horizontal=$(swaymsg -t get_outputs | jq ".[0].current_mode.width") + +convert $1 -resize ${horizontal}x${vertical}\> ~/.config/lockwall.png +convert ~/.config/lockwall.png -brightness-contrast -20,-20 -paint 1 -noise 0x8 -blur 9,9 ~/.config/lockwall.png +convert ~/.config/lockwall.png ~/.config/lock.png -gravity center -composite ~/.config/lockwall.png diff --git a/dotfiles/.local/bin/setbglsimple b/dotfiles/.local/bin/setbglsimple new file mode 100755 index 0000000..ea2c5f2 --- /dev/null +++ b/dotfiles/.local/bin/setbglsimple @@ -0,0 +1,7 @@ +#!/bin/sh + +vertical=$(($(xdotool getdisplaygeometry | awk '{print $2}') - newsize)) +horizontal=$(($(xdotool getdisplaygeometry | awk '{print $1}') - newwidth)) + +convert $1 -resize ${horizontal}x${vertical}\> ~/.config/lockwall.png +convert ~/.config/lockwall.png ~/.config/lock.png -gravity center -composite ~/.config/lockwall.png diff --git a/dotfiles/.local/bin/swaygetcurrentwindow b/dotfiles/.local/bin/swaygetcurrentwindow new file mode 100755 index 0000000..e6403a6 --- /dev/null +++ b/dotfiles/.local/bin/swaygetcurrentwindow @@ -0,0 +1,5 @@ +#!/bin/sh + +xydata=$(swaymsg -t get_tree | grep -B 5 '"focused": true' | head -n 4 | tr -d '\n\r' | sed -e 's/[^0-9,]//g' -e 's/,/ /2' -e 's/,/x/2') + +echo $xydata diff --git a/dotfiles/.local/bin/swaykbd b/dotfiles/.local/bin/swaykbd new file mode 100755 index 0000000..a76f833 --- /dev/null +++ b/dotfiles/.local/bin/swaykbd @@ -0,0 +1,20 @@ +#!/bin/sh + +swaymsg -r -t get_inputs | awk '/1:1:AT_Translated_Set_2_keyboard/;/xkb_active_layout_name/' | grep -A1 '\b1:1:AT_Translated_Set_2_keyboard\b' | grep "xkb_active_layout_name" | awk -F '"' '{print $4}' + +swaymsg \ + --type subscribe \ + --monitor \ + --raw \ + '["input"]' | \ + jq \ + --raw-output \ + --unbuffered \ ' + select(.change == "xkb_layout") | + .input.xkb_active_layout_name | + sub(" \\(US\\)"; "") + ' + +case $BLOCK_BUTTON in + 1) echo "TO-DO" ;; +esac; diff --git a/dotfiles/.local/bin/swayrecord b/dotfiles/.local/bin/swayrecord new file mode 100755 index 0000000..90ed24a --- /dev/null +++ b/dotfiles/.local/bin/swayrecord @@ -0,0 +1,14 @@ +#!/bin/sh + +if [ -f "$HOME/.recordingpid" ]; then + killall -SIGINT wf-recorder + rm -f ~/.recordingpid + notify-send "⏺ Screen recording" "Recording stopped" + killall -39 waybar + exit +fi + +wf-recorder -f "$HOME/Video/recordings/$(date '+%y%m%d-%H%M-%S').mp4" & +echo $! > ~/.recordingpid +notify-send "⏺ Screen recording" "Recording started" +killall -39 waybar diff --git a/dotfiles/.local/bin/swayresize b/dotfiles/.local/bin/swayresize new file mode 100755 index 0000000..9ae94c0 --- /dev/null +++ b/dotfiles/.local/bin/swayresize @@ -0,0 +1,27 @@ +#!/bin/sh +# This script was made by `goferito` on Github. +# Some cleanup by Luke. + +[ -z "$1" ] && echo "No direction provided" && exit 1 +distanceStr="2 px or 2 ppt" + +moveChoice() { + swaymsg resize "$1" "$2" "$distanceStr" | grep '"success":true' || \ + swaymsg resize "$3" "$4" "$distanceStr" +} + +case $1 in + up) + moveChoice grow up shrink down + ;; + down) + moveChoice shrink up grow down + ;; + left) + moveChoice shrink right grow left + ;; + right) + moveChoice grow right shrink left + ;; +esac + diff --git a/dotfiles/.local/bin/swaysession b/dotfiles/.local/bin/swaysession new file mode 100755 index 0000000..0507368 --- /dev/null +++ b/dotfiles/.local/bin/swaysession @@ -0,0 +1,35 @@ +#!/bin/sh +# /usr/bin/i3exit + +# on void just sudo +[[ $(cat /proc/1/comm) == "systemd" ]] && logind=systemctl || logind=loginctl + +case "$1" in + lock) + lock-color + ;; + logout) + swaymsg exit + ;; + switch_user) + dm-tool switch-to-greeter + ;; + suspend) + lock-color & sleep 1 && $logind suspend + ;; + hibernate) + lock-color & sleep 1 && $logind hibernate + ;; + reboot) + $logind reboot + ;; + poweroff) + $logind poweroff + ;; + *) + echo "== ! i3exit: missing or invalid argument ! ==" + echo "Try again with: lock | logout | switch_user | suspend | hibernate | reboot | shutdown" + exit 2 +esac + +exit 0 diff --git a/dotfiles/.local/bin/swaystart b/dotfiles/.local/bin/swaystart new file mode 100755 index 0000000..46f6f0e --- /dev/null +++ b/dotfiles/.local/bin/swaystart @@ -0,0 +1,12 @@ +#!/bin/sh + +export SCROT_DIR=$HOME/Pictures/screenshots/ +export GDK_BACKEND=wayland +export EGL_PLATFORM=wayland +export CLUTTER_PLATFORM=wayland +export SDL_VIDEODRIVER=wayland +export QT_QPA_PLATFORM=wayland-egl +export QT_WAYLAND_DISABLE_WINDOWDECORATION=1 +export QT_QPA_PLATFORMTHEME="qt5ct" +export _JAVA_AWT_WM_NONREPARENTING=1 +sway --my-next-gpu-wont-be-nvidia diff --git a/dotfiles/.local/bin/sxiv-rifle b/dotfiles/.local/bin/sxiv-rifle new file mode 100755 index 0000000..0bdd892 --- /dev/null +++ b/dotfiles/.local/bin/sxiv-rifle @@ -0,0 +1,48 @@ +#!/bin/sh +# Compatible with ranger 1.6.0 through 1.7.* +# +# This script searches image files in a directory, opens them all with sxiv and +# sets the first argument to the first image displayed by sxiv. +# +# This is supposed to be used in rifle.conf as a workaround for the fact that +# sxiv takes no file name arguments for the first image, just the number. Copy +# this file somewhere into your $PATH and add this at the top of rifle.conf: +# +# mime ^image, has sxiv, X, flag f = path/to/this/script -- "$@" +# +# Implementation notes: this script is quite slow because of POSIX limitations +# and portability concerns. First calling the shell function 'abspath' is +# quicker than calling 'realpath' because it would fork a whole process, which +# is slow. Second, we need to append a file list to sxiv, which can only be done +# properly in two ways: arrays (which are not POSIX) or \0 sperated +# strings. Unfortunately, assigning \0 to a variable is not POSIX either (will +# not work in dash and others), so we cannot store the result of listfiles to a +# variable. + +if [ $# -eq 0 ]; then + echo "Usage: ${0##*/} PICTURES" + exit +fi + +[ "$1" = '--' ] && shift + +abspath () { + case "$1" in + /*) printf "%s\n" "$1";; + *) printf "%s\n" "$PWD/$1";; + esac +} + +listfiles () { + find -L "$(dirname "$target")" -maxdepth 1 -type f -iregex \ + '.*\(jpe?g\|bmp\|png\|gif\)$' -print0 | sort -z +} + +target="$(abspath "$1")" +count="$(listfiles | grep -m 1 -ZznF "$target" | cut -d: -f1)" + +if [ -n "$count" ]; then + listfiles | xargs -0 sxiv -n "$count" -- +else + sxiv -- "$@" # fallback +fi diff --git a/dotfiles/.local/bin/texclear b/dotfiles/.local/bin/texclear new file mode 100755 index 0000000..6ead810 --- /dev/null +++ b/dotfiles/.local/bin/texclear @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +# Clears the build files of a LaTeX/XeLaTeX build. +# I have vim run this file whenever I exit a .tex file. + +case "$1" in + *.tex) + file=$(readlink -f "$1") + dir=$(dirname "$file") + base="${file%.*}" + find "$dir" -maxdepth 1 -type f -regextype gnu-awk -regex "^$base\\.(4tc|xref|tmp|pyc|pyo|fls|vrb|fdb_latexmk|bak|swp|aux|log|synctex\\(busy\\)|lof|lot|maf|idx|mtc|mtc0|nav|out|snm|toc|bcf|run\\.xml|synctex\\.gz|blg|bbl)" -delete ;; + *) printf "Give .tex file as argument.\\n" ;; +esac diff --git a/dotfiles/.local/bin/tlauncher b/dotfiles/.local/bin/tlauncher new file mode 100755 index 0000000..3699794 --- /dev/null +++ b/dotfiles/.local/bin/tlauncher @@ -0,0 +1,3 @@ +#!/bin/sh + +java -jar /opt/tlauncher/tlauncher.jar diff --git a/dotfiles/.local/bin/vifm_launch b/dotfiles/.local/bin/vifm_launch new file mode 100755 index 0000000..07b6473 --- /dev/null +++ b/dotfiles/.local/bin/vifm_launch @@ -0,0 +1,15 @@ +#!/bin/sh +export FIFO_UEBERZUG="/tmp/vifm-ueberzug-${PPID}" + +function cleanup { + rm "$FIFO_UEBERZUG" 2>/dev/null + pkill -P $$ 2>/dev/null +} + +rm "$FIFO_UEBERZUG" 2>/dev/null +mkfifo "$FIFO_UEBERZUG" +trap cleanup EXIT +tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser bash & + +vifm +cleanup diff --git a/dotfiles/.local/bin/waybar_launch b/dotfiles/.local/bin/waybar_launch new file mode 100755 index 0000000..6fc9200 --- /dev/null +++ b/dotfiles/.local/bin/waybar_launch @@ -0,0 +1,9 @@ +#!/bin/sh + +# Terminate already running bar instance +killall -q waybar + +# Wait until the processes have been shut down +while pgrep -u $UID -x waybar >/dev/null; do sleep 1; done + +waybar diff --git a/dotfiles/.local/bin/xway b/dotfiles/.local/bin/xway new file mode 100755 index 0000000..a6008c6 --- /dev/null +++ b/dotfiles/.local/bin/xway @@ -0,0 +1,11 @@ +#!/bin/sh + +# Certain Xorg apps require certain env variable to correctly work through xwayland + +export GDK_BACKEND=x11 +export EGL_PLATFORM=x11 +export CLUTTER_PLATFORM=x11 +export SDL_VIDEODRIVER=x11 +export QT_QPA_PLATFORM=xcb + +$1 |