diff options
| author | krolyxon <krolyxon@tutanota.com> | 2022-06-01 22:55:52 +0530 |
|---|---|---|
| committer | krolyxon <krolyxon@tutanota.com> | 2022-06-01 22:55:52 +0530 |
| commit | 723220028038a3c6e155259e28d07e867e2d45c9 (patch) | |
| tree | f07e13aaf23e820c6da71ec02466e5831502b0e2 /.local/bin | |
first commit
Diffstat (limited to '.local/bin')
| -rwxr-xr-x | .local/bin/colorpicker | bin | 0 -> 23168 bytes | |||
| -rwxr-xr-x | .local/bin/connect_wifi | 5 | ||||
| -rwxr-xr-x | .local/bin/dmenumount | 67 | ||||
| -rwxr-xr-x | .local/bin/ext | 45 | ||||
| -rwxr-xr-x | .local/bin/genwall | 18 | ||||
| -rwxr-xr-x | .local/bin/linkhandler | 23 | ||||
| -rwxr-xr-x | .local/bin/maimshot | 11 | ||||
| -rwxr-xr-x | .local/bin/newword | 6 | ||||
| -rwxr-xr-x | .local/bin/setwall | 5 | ||||
| -rwxr-xr-x | .local/bin/spammer | 9 | ||||
| -rwxr-xr-x | .local/bin/spot-adblock | 2 | ||||
| -rwxr-xr-x | .local/bin/transadd | 9 | ||||
| -rwxr-xr-x | .local/bin/ufetch | 83 | ||||
| -rwxr-xr-x | .local/bin/unicode_emoji | 13 | ||||
| -rwxr-xr-x | .local/bin/upfile | 12 | ||||
| -rwxr-xr-x | .local/bin/vimv | 44 | ||||
| -rwxr-xr-x | .local/bin/waldl | 158 | ||||
| -rwxr-xr-x | .local/bin/wordmean | 6 |
18 files changed, 516 insertions, 0 deletions
diff --git a/.local/bin/colorpicker b/.local/bin/colorpicker Binary files differnew file mode 100755 index 0000000..ab19d07 --- /dev/null +++ b/.local/bin/colorpicker diff --git a/.local/bin/connect_wifi b/.local/bin/connect_wifi new file mode 100755 index 0000000..3b4d5f8 --- /dev/null +++ b/.local/bin/connect_wifi @@ -0,0 +1,5 @@ +#!/bin/sh + +bssid=$(nmcli device wifi list | sed -n '1!p' | cut -b 9- | dmenu -p "Select wifi:" -l 20 | cut -d' ' -f1) +pass=$(echo "" | dmenu -P -p "Enter Password: ") +nmcli device wifi connect $bssid password $pass diff --git a/.local/bin/dmenumount b/.local/bin/dmenumount new file mode 100755 index 0000000..b414dc8 --- /dev/null +++ b/.local/bin/dmenumount @@ -0,0 +1,67 @@ +#!/bin/sh + +# Gives a dmenu prompt to mount unmounted drives and Android phones. If +# they're in /etc/fstab, they'll be mounted automatically. Otherwise, you'll +# be prompted to give a mountpoint from already existsing directories. If you +# input a novel directory, it will prompt you to create that directory. + +getmount() { \ + [ -z "$chosen" ] && exit 1 + # shellcheck disable=SC2086 + mp="$(find $1 2>/dev/null | dmenu -i -p "Type in mount point.")" || exit 1 + test -z "$mp" && exit 1 + if [ ! -d "$mp" ]; then + mkdiryn=$(printf "No\\nYes" | dmenu -i -p "$mp does not exist. Create it?") || exit 1 + [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp") + fi + } + +mountusb() { \ + chosen="$(echo "$usbdrives" | dmenu -i -p "Mount which drive?")" || exit 1 + chosen="$(echo "$chosen" | awk '{print $1}')" + sudo -A mount "$chosen" 2>/dev/null && notify-send "💻 USB mounting" "$chosen mounted." && exit 0 + alreadymounted=$(lsblk -nrpo "name,type,mountpoint" | awk '$3!~/\/boot|\/home$|SWAP/&&length($3)>1{printf "-not ( -path *%s -prune ) ",$3}') + getmount "/mnt /media /mount /home -maxdepth 5 -type d $alreadymounted" + partitiontype="$(lsblk -no "fstype" "$chosen")" + case "$partitiontype" in + "vfat") sudo -A mount -t vfat "$chosen" "$mp" -o rw,umask=0000;; + "exfat") sudo -A mount "$chosen" "$mp" -o uid="$(id -u)",gid="$(id -g)";; + *) sudo -A mount "$chosen" "$mp"; user="$(whoami)"; ug="$(groups | awk '{print $1}')"; sudo -A chown "$user":"$ug" "$mp";; + esac + notify-send "💻 USB mounting" "$chosen mounted to $mp." + } + +mountandroid() { \ + chosen="$(echo "$anddrives" | dmenu -i -p "Which Android device?")" || exit 1 + chosen="$(echo "$chosen" | cut -d : -f 1)" + getmount "$HOME -maxdepth 3 -type d" + simple-mtpfs --device "$chosen" "$mp" + echo "OK" | dmenu -i -p "Tap Allow on your phone if it asks for permission and then press enter" || exit 1 + simple-mtpfs --device "$chosen" "$mp" + notify-send "🤖 Android Mounting" "Android device mounted to $mp." + } + +asktype() { \ + choice="$(printf "USB\\nAndroid" | dmenu -i -p "Mount a USB drive or Android device?")" || exit 1 + case $choice in + USB) mountusb ;; + Android) mountandroid ;; + esac + } + +anddrives=$(simple-mtpfs -l 2>/dev/null) +usbdrives="$(lsblk -rpo "name,type,size,mountpoint" | grep 'part\|rom' | awk '$4==""{printf "%s (%s)\n",$1,$3}')" + +if [ -z "$usbdrives" ]; then + [ -z "$anddrives" ] && echo "No USB drive or Android device detected" && exit + echo "Android device(s) detected." + mountandroid +else + if [ -z "$anddrives" ]; then + echo "USB drive(s) detected." + mountusb + else + echo "Mountable USB drive(s) and Android device(s) detected." + asktype + fi +fi
\ No newline at end of file diff --git a/.local/bin/ext b/.local/bin/ext new file mode 100755 index 0000000..9810c83 --- /dev/null +++ b/.local/bin/ext @@ -0,0 +1,45 @@ +#!/bin/sh + +# A general, all-purpose extraction script. Not all extraction programs here +# are installed by LARBS automatically. +# +# Default behavior: Extract archive into new directory +# Behavior with `-c` option: Extract contents into current directory + +while getopts "hc" o; do case "${o}" in + c) extracthere="True" ;; + *) printf "Options:\\n -c: Extract archive into current directory rather than a new one.\\n" && exit 1 ;; +esac done + +if [ -z "$extracthere" ]; then + archive="$(readlink -f "$*")" && + directory="$(echo "$archive" | sed 's/\.[^\/.]*$//')" && + mkdir -p "$directory" && + cd "$directory" || exit 1 +else + archive="$(readlink -f "$(echo "$*" | cut -d' ' -f2)" 2>/dev/null)" +fi + +[ -z "$archive" ] && printf "Give archive to extract as argument.\\n" && exit 1 + +if [ -f "$archive" ] ; then + case "$archive" in + *.tar.bz2|*.tbz2) bsdtar -xf "$archive" ;; + *.tar.xz) bsdtar -xf "$archive" ;; + *.tar.gz|*.tgz) bsdtar -xf "$archive" ;; + *.tar.zst) bsdtar -xf "$archive" ;; + *.tar) bsdtar -xf "$archive" ;; + *.lzma) unlzma "$archive" ;; + *.bz2) bunzip2 "$archive" ;; + *.rar) unrar x -ad "$archive" ;; + *.gz) gunzip "$archive" ;; + *.zip) unzip "$archive" ;; + *.Z) uncompress "$archive" ;; + *.7z) 7z x "$archive" ;; + *.xz) unxz "$archive" ;; + *.exe) cabextract "$archive" ;; + *) printf "extract: '%s' - unknown archive method\\n" "$archive" ;; + esac +else + printf "File \"%s\" not found.\\n" "$archive" +fi
\ No newline at end of file diff --git a/.local/bin/genwall b/.local/bin/genwall new file mode 100755 index 0000000..ccbe75e --- /dev/null +++ b/.local/bin/genwall @@ -0,0 +1,18 @@ +#!/bin/sh + +# Dependencies: +# convert wal xdotool xwallpaper + +wall_dir=~/pix/wall + +if [ -z "$1" ]; then + wall="$(find "$wall_dir" -type f -name "*.jpg" -o -name "*.png" | shuf -n1)" +else + wall="$1" +fi + +convert "$wall" ~/.local/share/bg.jpg +xwallpaper --zoom ~/.local/share/bg.jpg +wal -c +wal -i ~/.local/share/bg.jpg +xdotool key super+F5 diff --git a/.local/bin/linkhandler b/.local/bin/linkhandler new file mode 100755 index 0000000..fa74caf --- /dev/null +++ b/.local/bin/linkhandler @@ -0,0 +1,23 @@ +#!/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/watch*|*youtube.com/playlist*|*youtu.be*|*hooktube.com*|*bitchute.com*|*videos.lukesmith.xyz*|*odysee.com*) + setsid -f mpv -quiet "$1" >/dev/null 2>&1 ;; + *png|*jpg|*jpe|*jpeg|*gif) + curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" && sxiv -a "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 & ;; + *pdf|*cbz|*cbr) + curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" && zathura "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 & ;; + *mp3|*flac|*opus|*mp3?source*) + qndl "$1" 'curl -LO' >/dev/null 2>&1 ;; + *) + [ -f "$1" ] && setsid -f "$TERMINAL" -e "$EDITOR" "$1" >/dev/null 2>&1 || setsid -f "$BROWSER" "$1" >/dev/null 2>&1 +esac diff --git a/.local/bin/maimshot b/.local/bin/maimshot new file mode 100755 index 0000000..10335f6 --- /dev/null +++ b/.local/bin/maimshot @@ -0,0 +1,11 @@ +#!/bin/sh + +case "$(printf "a selected area (copy)\\ncurrent window (copy)\\nfull screen (copy)\\na selected area\\ncurrent window\\nfull screen" | dmenu -l 6 -i -p "Screenshot which area?")" in + "a selected area (copy)") maim -s | xclip -selection clipboard -t image/png ;; + "current window (copy)") maim -i "$(xdotool getactivewindow)" | xclip -selection clipboard -t image/png ;; + "full screen (copy)") sleep 0.2 ; maim | xclip -selection clipboard -t image/png ;; + "a selected area") maim -s ~/pix/ss/pic-selected-"$(date '+%y-%m-%d-%H-%M').png" ;; + "current window") maim -i "$(xdotool getactivewindow)" ~/pix/ss/pic-window-"$(date '+%y-%m-%d-%H-%M').png" ;; + "full screen") sleep 0.2 ; maim ~/pix/ss/pic-full-"$(date '+%y-%m-%d-%H-%M').png" ;; + +esac diff --git a/.local/bin/newword b/.local/bin/newword new file mode 100755 index 0000000..dc44076 --- /dev/null +++ b/.local/bin/newword @@ -0,0 +1,6 @@ +#!/bin/sh + +word=$(dmenu -p "Enter Word: " <&-) +mean=$(dmenu -p "Enter Meaning: " <&-) + +echo "$word -> $mean" >> ~/.local/share/vocab/words.txt
\ No newline at end of file diff --git a/.local/bin/setwall b/.local/bin/setwall new file mode 100755 index 0000000..35b5f06 --- /dev/null +++ b/.local/bin/setwall @@ -0,0 +1,5 @@ +#!/bin/sh +xwallpaper --zoom ~/.local/share/bg.jpg +wal -c +wal -i ~/.local/share/bg.jpg +xdotool key super+F5 diff --git a/.local/bin/spammer b/.local/bin/spammer new file mode 100755 index 0000000..c23a81c --- /dev/null +++ b/.local/bin/spammer @@ -0,0 +1,9 @@ +#!/bin/sh + +i=0 + +while [ $i -le 100 ] +do + xdotool type "$1" ;xdotool key KP_Enter; sleep 1 ; + +done diff --git a/.local/bin/spot-adblock b/.local/bin/spot-adblock new file mode 100755 index 0000000..c68a75c --- /dev/null +++ b/.local/bin/spot-adblock @@ -0,0 +1,2 @@ +#!/bin/sh +LD_PRELOAD=/usr/local/lib/spotify-adblock.so spotify diff --git a/.local/bin/transadd b/.local/bin/transadd new file mode 100755 index 0000000..ffa31fb --- /dev/null +++ b/.local/bin/transadd @@ -0,0 +1,9 @@ +#!/bin/sh + +# Mimeapp script for adding torrent to transmission-daemon, but will also start the daemon first if not running. + +# transmission-daemon sometimes fails to take remote requests in its first moments, hence the sleep. + +pidof transmission-daemon >/dev/null || (transmission-daemon && notify-send "Starting transmission daemon...") +sleep 3 +transmission-remote -a "$@" && notify-send "🔽 Torrent added." diff --git a/.local/bin/ufetch b/.local/bin/ufetch new file mode 100755 index 0000000..eb29af3 --- /dev/null +++ b/.local/bin/ufetch @@ -0,0 +1,83 @@ +#!/bin/sh +# +# ufetch-arch - tiny system info for arch + +## INFO + +# user is already defined +host="$(cat /etc/hostname)" +os='Arch Linux' +kernel="$(uname -sr)" +uptime="$(uptime -p | sed 's/up //')" +packages="$(pacman -Q | wc -l)" +shell="$(basename "${SHELL}")" + +## UI DETECTION + +parse_rcs() { + for f in "${@}"; do + wm="$(tail -n 1 "${f}" 2> /dev/null | cut -d ' ' -f 2)" + [ -n "${wm}" ] && echo "${wm}" && return + done +} + +rcwm="$(parse_rcs "${HOME}/.xinitrc" "${HOME}/.xsession")" + +ui='unknown' +uitype='UI' +if [ -n "${DE}" ]; then + ui="${DE}" + uitype='DE' +elif [ -n "${WM}" ]; then + ui="${WM}" + uitype='WM' +elif [ -n "${XDG_CURRENT_DESKTOP}" ]; then + ui="${XDG_CURRENT_DESKTOP}" + uitype='DE' +elif [ -n "${DESKTOP_SESSION}" ]; then + ui="${DESKTOP_SESSION}" + uitype='DE' +elif [ -n "${rcwm}" ]; then + ui="${rcwm}" + uitype='WM' +elif [ -n "${XDG_SESSION_TYPE}" ]; then + ui="${XDG_SESSION_TYPE}" +fi + +ui="$(basename "${ui}")" + +## DEFINE COLORS + +# probably don't change these +if [ -x "$(command -v tput)" ]; then + bold="$(tput bold)" + black="$(tput setaf 0)" + red="$(tput setaf 1)" + green="$(tput setaf 2)" + yellow="$(tput setaf 3)" + blue="$(tput setaf 4)" + magenta="$(tput setaf 5)" + cyan="$(tput setaf 6)" + white="$(tput setaf 7)" + reset="$(tput sgr0)" +fi + +# you can change these +lc="${reset}${bold}${blue}" # labels +nc="${reset}${bold}${blue}" # user and hostname +ic="${reset}" # info +c0="${reset}${blue}" # first color + +## OUTPUT + +cat <<EOF + +${c0} /\\ ${nc}${USER}${ic}@${nc}${host}${reset} +${c0} / \\ ${lc}OS: ${ic}${os}${reset} +${c0} /\\ \\ ${lc}KERNEL: ${ic}${kernel}${reset} +${c0} / __ \\ ${lc}UPTIME: ${ic}${uptime}${reset} +${c0} / ( ) \\ ${lc}PACKAGES: ${ic}${packages}${reset} +${c0} / __| |__\\\\ ${lc}SHELL: ${ic}${shell}${reset} +${c0} /.\` \`.\\ ${lc}${uitype}: ${ic}${ui}${reset} + +EOF diff --git a/.local/bin/unicode_emoji b/.local/bin/unicode_emoji new file mode 100755 index 0000000..415a268 --- /dev/null +++ b/.local/bin/unicode_emoji @@ -0,0 +1,13 @@ +#!/bin/sh + +# The famous "get a menu of emojis to copy" script. + +# Get user selection via dmenu from emoji file. +chosen=$(cut -d ';' -f1 ~/.local/share/emoji | dmenu -i -l 30 | sed "s/ .*//") + +# Exit if none chosen. +[ -z "$chosen" ] && exit + +xdotool type "$chosen" +printf "$chosen" | xclip -selection clipboard +notify-send "'$chosen' copied to clipboard." &
\ No newline at end of file diff --git a/.local/bin/upfile b/.local/bin/upfile new file mode 100755 index 0000000..4196dc5 --- /dev/null +++ b/.local/bin/upfile @@ -0,0 +1,12 @@ +#!/bin/sh + +if [ -n "$1" ]; then + file=$1 +else + file=$(find . -maxdepth 2 -type f | fzf) +fi + +[ -z "$file" ] && exit + +curl -F"file=@$file" 0x0.st | xclip -sel c +notify-send "The url has been copied to your clipboard." diff --git a/.local/bin/vimv b/.local/bin/vimv new file mode 100755 index 0000000..74844fc --- /dev/null +++ b/.local/bin/vimv @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +set -eu + +# Lists the current directory's files in Vim, so you can edit it and save to rename them +# USAGE: vimv [file1 file2] +# https://github.com/thameera/vimv + +declare -r FILENAMES_FILE=$(mktemp "${TMPDIR:-/tmp}/vimv.XXX") + +trap '{ rm -f "${FILENAMES_FILE}" ; }' EXIT + +if [ $# -ne 0 ]; then + src=( "$@" ) +else + IFS=$'\r\n' GLOBIGNORE='*' command eval 'src=($(ls))' +fi + +for ((i=0;i<${#src[@]};++i)); do + echo "${src[i]}" >> "${FILENAMES_FILE}" +done + +${EDITOR:-vi} "${FILENAMES_FILE}" + +IFS=$'\r\n' GLOBIGNORE='*' command eval 'dest=($(cat "${FILENAMES_FILE}"))' + +if (( ${#src[@]} != ${#dest[@]} )); then + echo "WARN: Number of files changed. Did you delete a line by accident? Aborting.." >&2 + exit 1 +fi + +declare -i count=0 +for ((i=0;i<${#src[@]};++i)); do + if [ "${src[i]}" != "${dest[i]}" ]; then + mkdir -p "$(dirname "${dest[i]}")" + if git ls-files --error-unmatch "${src[i]}" > /dev/null 2>&1; then + git mv "${src[i]}" "${dest[i]}" + else + mv "${src[i]}" "${dest[i]}" + fi + ((++count)) + fi +done + +echo "$count" files renamed. diff --git a/.local/bin/waldl b/.local/bin/waldl new file mode 100755 index 0000000..1957354 --- /dev/null +++ b/.local/bin/waldl @@ -0,0 +1,158 @@ +#!/bin/sh + +# https://github.com/pystardust/waldl +# script to find and download wallpapers from wallhaven +version="0.0.1" + +# Usage: +# waldl <query> +# if query left empty then sh_menu will be used (dmenu by default) +# after the thumbnails are cached, sxiv would open up with the thumbnails +# Select the wallpapers using `m` on the image. ( marking the image in sxiv ) +# press `q` to quit sxiv, the marked images would start downloading + +#################### +## User variables ## +#################### + +# the dir where wallpapers are stored +walldir="$HOME/pix/wallhaven" +# the dir used to cache thumbnails +cachedir="$HOME/.cache/wallhaven" +# sxiv options +sxiv_otps=" -tfpo -z 200" # o is needed for selection +# number of pages to show in search results +# each page contains 24 results +max_pages=4 +# sorting : date_added, relevance, random, views, favorites, toplist +sorting=relevance +# quality : large original small +quality=large +# atleast : least res +atleast=1920x1080 + +# the menu command used when no query is provided +sh_menu () { + : | dmenu -p "search wallhaven: " + # ROFI: comment the previous line and uncomment the next line for rofi + # rofi -dmenu -l 0 -p "search wallpapers" +} + +########################## +## getting search query ## +########################## + +[ -n "$*" ] && query="$*" || query=$( sh_menu ) +[ -z "$query" ] && exit 1 +query=$(printf '%s' "$query" | tr ' ' '+' ) + +###################### +## start up commands # +###################### + +rm -rf "$cachedir" +mkdir -p "$walldir" "$cachedir" + +# progress display command +sh_info () { + printf "%s\n" "$1" >&2 + notify-send "wallhaven" "$1" + [ -n "$2" ] && exit "$2" +} + +# dependency checking +dep_ck () { + for pr; do + command -v $pr >/dev/null 2>&1 || sh_info "command $pr not found, install: $pr" 1 + done +} +dep_ck "sxiv" "curl" "jq" + + +# clean up command that would be called when the program exits +clean_up () { + printf "%s\n" "cleaning up..." >&2 + rm -rf "$datafile" "$cachedir" +} + +# data file to store the api information +datafile="/tmp/wald.$$" + +# clean up if killed +trap "exit" INT TERM +trap "clean_up" EXIT + +################## +## getting data ## +################## + +# request the search results for each page +get_results () { + for page_no in $(seq $max_pages) + do + { + json=$(curl -s -G "https://wallhaven.cc/api/v1/search" \ + -d "q=$1" \ + -d "page=$page_no" \ + -d "atleast=$atleast" \ + -d "sorting=$sorting" + ) + printf "%s\n" "$json" >> "$datafile" + } & + sleep 0.001 + done + wait +} + +# search wallpapers +sh_info "getting data..." +get_results "$query" + +# check if data file is empty, if so then exit +[ -s "$datafile" ] || sh_info "no images found" 1 + +############################ +## downloading thumbnails ## +############################ + +# get a list of thumnails from the data +thumbnails=$( jq -r '.data[]?|.thumbs.'"$quality" < "$datafile") + +[ -z "$thumbnails" ] && sh_info "no-results found" 1 + +# download the thumbnails +sh_info "caching thumbnails..." +for url in $thumbnails +do + printf "url = %s\n" "$url" + printf "output = %s\n" "$cachedir/${url##*/}" +done | curl -Z -K - +#sh_info "downloaded thumbnails..." + +########################### +## user selection (sxiv) ## +########################### + +# extract the id's out of the thumbnail name +image_ids="$(sxiv $sxiv_otps "$cachedir")" +[ -z "$image_ids" ] && exit + +######################### +## download wallpapers ## +######################### + +# download the selected wall papers +mkdir "$walldir/$query" +cd "$walldir/$query" +sh_info "downloading wallpapers..." +for ids in $image_ids +do + ids="${ids##*/}" + ids="${ids%.*}" + url=$( jq -r '.data[]?|select( .id == "'$ids'" )|.path' < "$datafile" ) + printf "url = %s\n" "$url" + printf -- "-O\n" +done | curl -K - + +sh_info "wallpapers downloaded in:- '$walldir/$query'" +sxiv $(ls -c) diff --git a/.local/bin/wordmean b/.local/bin/wordmean new file mode 100755 index 0000000..e8f5f4e --- /dev/null +++ b/.local/bin/wordmean @@ -0,0 +1,6 @@ +#!/bin/sh + +word=$(dmenu -p "Enter Word: " <&-) +#$BROWSER https://www.merriam-webster.com/dictionary/$word +$BROWSER "https://www.google.com/search?hl=en&q=define+$word" + |
