~seirdy/dotfiles

fff602f6a4581419d866effe2f4571903480e07c — Rohan Kumar 8 months ago d8e2863
Replace some functions with executable scripts

These functions don't need to alter my environment. Furthermore, I don't
want to have to re-source a file every time I alter these. I'd also like
to have them in my $PATH so that all programs can access them.
M .config/shell_common/functions.sh => .config/shell_common/functions.sh +4 -88
@@ 17,15 17,6 @@ wdir() {
	cd "$progdir" || return
}

cdg() {
	if [ -z "$1" ]; then
		cdto=$(ghq list | fzf)
	else
		cdto=$(ghq list | fzf -q "$@")
	fi
	[ "$cdto" = '' ] || cd "$GHQ_ROOT/$cdto" || return 1
}

history_stats() {
	if [ -z "$1" ]; then
		entries=1000


@@ 42,7 33,6 @@ history_stats() {
}

pf() {
	local pid
	pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')

	if [ "x$pid" != "x" ]; then


@@ 52,7 42,6 @@ pf() {

# list only the ones you can kill. Modified the earlier script.
pfu() {
	local pid uid
	uid=$(bash -c 'echo $UID')
	if [ "$uid" != "0" ]; then
		pid=$(ps -f -u "$uid" | sed 1d | fzf -m -q "$@" | awk '{print $2}')


@@ 66,7 55,6 @@ pfu() {
}

fkill() {
	local signal
	if [ $# -eq 0 ]; then
		signal=9
	else


@@ 87,7 75,6 @@ jqy() {

# Start and attach to a docker container
da() {
	local cid
	cid=$(docker ps -a | sed 1d | fzf -1 -q "$1" | awk '{print $1}')

	[ -n "$cid" ] && docker start "$cid" && docker attach "$cid"


@@ 95,68 82,15 @@ da() {

# Select a running docker container to stop
ds() {
	local cid
	cid=$(docker ps | sed 1d | fzf -q "$1" | awk '{print $1}')

	[ -n "$cid" ] && docker stop "$cid"
}

fbuku() {
	bmark=$(buku -p -f 5 | fzf --tac)
	index="$(echo "$bmark" | awk '{print $1}')"
	echo "index is $index"
	buku -p "$index"
	buku -o "$index"
}

bcalc() {
	echo "scale=10; $*" | bc -l
}
# shellcheck source=file_mngment.sh
# shellcheck source=/home/rkumar/startup.sh
# shellcheck source=/home/rkumar/.config/shell_common/file_mngment.sh
. "$XDG_CONFIG_HOME/shell_common/file_mngment.sh"

# file uploading/pastebins

imgurup() {
	json_data="$(curl -H "Referer: https://imgur.com/upload" -F "Filedata=@$1" https://imgur.com/upload | jq -r '.data')"
	hash="$(echo "$json_data" | jq -r '.hashes | .[]')"
	ext="$(echo "$json_data" | jq -r '.ext')"
	echo "https://imgur.kageurufu.net/${hash}${ext}"
}

upl() {
	curl-tor --progress -F"file=@$1" https://0x0.st
}

# shareit: upload stdin to https://share.schollz.com.
# Generates a random filename if one is not provided.
shareit() {
	[ -n "$1" ] && filename="$1" || filename="$(tr -dc A-Za-z0-9 </dev/urandom | head -c 10)"
	curl-tor --progress --upload-file - "https://share.schollz.com/$filename" | sed 's#schollz\.com#schollz\.com/1#'
}

# `curlout <url> | clbin` will mirror <url> to clbin.
curlout() {
	curl-tor --progress "$@" --output -
}

# save chattiest-channels to a pastebin
share-chattiest-channels() {
	{
		chattiest-channels "$@"
		printf "\nIf you run weechat then you can run this yourself: https://git.sr.ht/~seirdy/chattiest-channels"
	} | curl-tor --progress -F "clbin=<-" https://clbin.com | wl-copy -n \
		&& wl-paste \
		&& curl-tor $(wl-paste)

}

hnopen() {
	for URL in "$@"; do
		hn view -bc "$URL"
	done
}

dnfbadstr1='^(mingw(32|64)|R-)|(\.(src|i686)|debug(info|source)\..*)$'
dnfbadstr2='^(mingw(32|64)|R-|lib|perl|python|texlive)|(\.(src|i686)|(\-(devel|doc|common)|debug(info|source)\..*))$'



@@ 187,25 121,7 @@ gitssearch() {
	$BROWSER "$(_ghsearch_starred_url "$*")"
}

unshorten() {
	curl "https://unshorten.me/s/$1"
}

unshorten_clip() {
	unshorten "$(wl-paste)" | head -n 1 | wl-copy
}

isitup() {
	curl-tor "https://isitup.org/$1.json" -s | jq
}

# set up a git repo
git_setup() {
	git init
	git remote add origin "https://gitlab.com/Seirdy/$1.git"
	git remote add gh_mirror "https://gitlab.com/Seirdy/$1.git"
}

# shellcheck source=functions_ghq.sh
# shellcheck source=/home/rkumar/.config/shell_common/functions_ghq.sh
. "$(dirname "$0")/functions_ghq.sh"
# shellcheck source=/home/rkumar/.config/shell_common/pash.sh
. "$(dirname "$0")/pash.sh"

A Executables/shell-scripts/bin/bcalc => Executables/shell-scripts/bin/bcalc +6 -0
@@ 0,0 1,6 @@
#!/usr/bin/env dash

# nobody likes typing "echo ... | bc -l" so this wraps that for convenience
echo "$*" | bc -l

# vi:ft=sh

A Executables/shell-scripts/bin/cdg => Executables/shell-scripts/bin/cdg +12 -0
@@ 0,0 1,12 @@
#!/usr/bin/env dash
# cd to a git repo managed by ghq
if [ -z "$1" ]; then
	cdto=$(ghq list | fzf)
else
	cdto=$(ghq list | fzf -q "$@")
fi
# shellcheck disable=SC2154
[ "$cdto" = '' ] || cd "$GHQ_ROOT/$cdto" || return 1

# vi:ft=sh


A Executables/shell-scripts/bin/curlout => Executables/shell-scripts/bin/curlout +8 -0
@@ 0,0 1,8 @@
#!/usr/bin/env dash

# `curlout <url> | clbin` will mirror <url> to clbin.
curlout() {
	curl-tor --progress "$@" --output -
}

# vi:ft=sh

A Executables/shell-scripts/bin/fbuku => Executables/shell-scripts/bin/fbuku +10 -0
@@ 0,0 1,10 @@
#!/usr/bin/env dash

# buku + fzf
bmark="$(buku -p -f 5 | fzf --tac)"
index="$(echo "$bmark" | awk '{print $1}')"
echo "index is $index"
buku -p "$index"
buku -o "$index"

# vi:ft=sh

A Executables/shell-scripts/bin/git-remote-setup => Executables/shell-scripts/bin/git-remote-setup +10 -0
@@ 0,0 1,10 @@
#!/usr/bin/env dash

# Initialize a git repo and add my remotes
# Remotes include the main sourcehut remote + GitLab/GitHub mirrors.
git init
git remote add origin "git@git.sr.ht:~seirdy/$1"
git remote add gl_mirror "git@gitlab.com:Seirdy/$1.git"
git remote add gh_mirror "git@github.com:Seirdy/$1.git"

# vi:ft=sh

M Executables/shell-scripts/bin/godoc-gomod => Executables/shell-scripts/bin/godoc-gomod +1 -1
@@ 1,6 1,6 @@
#!/usr/bin/env dash
# Runs godoc for a project using go modules instead of $GOPATH
module=$(awk 'NR==1{print $2}' go.mod)
docker run --rm -e "GOPATH=/tmp/go" -p 6060:6060 -v $(pwd):/tmp/go/src/$module golang:latest /bin/bash -c "awk 'END{print \"http://\"\$1\":6060/pkg/$module\"}' /etc/hosts && godoc -http=:6060"
podman run --rm -e "GOPATH=/tmp/go" -p 6060:6060 -v "$(pwd):/tmp/go/src/$module" golang:latest /bin/bash -c "awk 'END{print \"http://\"\$1\":6060/pkg/$module\"}' /etc/hosts && godoc -http=:6060"

# vim:ft=sh

A Executables/shell-scripts/bin/hnopen => Executables/shell-scripts/bin/hnopen +8 -0
@@ 0,0 1,8 @@
#!/usr/bin/env dash

# open a list of hacker news IDs
for id in "$@"; do
	hn view -bc "$id"
done

# vi:ft=sh

A Executables/shell-scripts/bin/imgurup => Executables/shell-scripts/bin/imgurup +9 -0
@@ 0,0 1,9 @@
#!/usr/bin/env dash

json_data="$(curl -H "Referer: https://imgur.com/upload" -F "Filedata=@$1" https://imgur.com/upload | jq -r '.data')"
echo "$json_data"
hash="$(echo "$json_data" | jq -r '.hashes | .[]')"
ext="$(echo "$json_data" | jq -r '.ext')"
echo "https://imgur.kageurufu.net/${hash}${ext}"

# vi:ft=sh

A Executables/shell-scripts/bin/isitup => Executables/shell-scripts/bin/isitup +7 -0
@@ 0,0 1,7 @@
#!/usr/bin/env dash

# use isitup.org to see whether or not a website is down
curl-tor "https://isitup.org/$1.json" -s | jq


# vi:ft=sh

M Executables/shell-scripts/bin/new-executable => Executables/shell-scripts/bin/new-executable +5 -1
@@ 1,7 1,11 @@
#!/usr/bin/env dash
# vi:ft=sh
newfile="$HOME/Executables/shell-scripts/bin/$1"
[ -e "$newfile" ] && echo "error: file exists" 1>&2 && exit 1
printf '#!/usr/bin/env dash\n\n# vi:ft=sh' >"$newfile"
chmod +x "$newfile"
# shellcheck source=/home/rkumar/startup.sh
# shellcheck disable=SC2154
$EDITOR "$newfile"
if [ "$2" = '-g' ]; then
	yadm add "$newfile"
fi

M Executables/shell-scripts/bin/new-note => Executables/shell-scripts/bin/new-note +1 -0
@@ 8,6 8,7 @@ date: '$(date -I)'
---

# " >"$newfile"
# shellcheck disable=SC2154
$EDITOR "$newfile"

# Example output:

M Executables/shell-scripts/bin/nwrap => Executables/shell-scripts/bin/nwrap +1 -0
@@ 4,6 4,7 @@ export NNN_BMS="D:~/Downloads;v:~/Videos"

export NNN_CONTEXT_COLORS="5236"

# shellcheck disable=SC2154
alias nsel="cat \${XDG_CONFIG_HOME:-\$HOME/.config}/nnn/.selection | tr '\0' '\n'"

# Unmask ^Q (if required, see `stty -a`) to Quit nnn

M Executables/shell-scripts/bin/reddio-url => Executables/shell-scripts/bin/reddio-url +1 -1
@@ 1,5 1,5 @@
#!/usr/bin/env dash

# Reddio command $1 on $2, $2 being a link to a Reddit thread
reddio $1 "comments/${2#*/comments/}"
reddio "$1" "comments/${2#*/comments/}"
# vi:ft=sh

M Executables/shell-scripts/bin/rsync-to-lappie => Executables/shell-scripts/bin/rsync-to-lappie +11 -13
@@ 5,18 5,16 @@
cd || exit 1

# Update binaries
rsync -zlrupP ~/Executables/stack/bin rkumar@rkumarlappie:/home/rkumar/Executables/stack
rsync -zlrupP ~/Executables/go/bin rkumar@rkumarlappie:/home/rkumar/Executables/go
rsync -zlrupP ~/Executables/lappie/cargo/bin rkumar@rkumarlappie:/home/rkumar/Executables/cargo
rsync -lrupP ~/.local/man rkumar@rkumarlappie:/home/rkumar/.local
rsync -lrupP ~/.local/include rkumar@rkumarlappie:/home/rkumar/.local
rsync -zlrupP ~/.local/libexec/cni ~/.local/libexec/revokefs-fuse rkumar@rkumarlappie:/home/rkumar/.local
rsync -zlrupP --exclude '.local/lib/python*' ~/.local/lib rkumar@rkumarlappie:/home/rkumar/.local
rsync -lrupP ~/.local/share/man rkumar@rkumarlappie:/home/rkumar/.local/share
rsync -zlrupP --skip-compress=cmdline/search/queue ~/.local/share/newsboat rkumar@rkumarlappie:/home/rkumar/.local/share
rsync -lrupP ~/.local/share/buku rkumar@rkumarlappie:/home/rkumar/.local/share
rsync -zlrupP ~/.local/bin/fuse-overlayfs ~/.local/bin/fusermount3 rkumar@rkumarlappie:/home/rkumar/.local/bin
# rsync -zlrupP --exclude "$(git ls-files .local/bin | tr '\n' ' ' | sed 's/ \./ --exclude \./g')" ~/.local/bin rkumar@rkumarlappie:/home/rkumar/.local
rsync -azuP ~/Executables/stack/bin rkumar@rkumarlappie:/home/rkumar/Executables/stack &
rsync -auP ~/.local/include rkumar@rkumarlappie:/home/rkumar/.local &
rsync -azuP ~/Executables/go/bin rkumar@rkumarlappie:/home/rkumar/Executables/go
rsync -azuP --exclude 'bin/alacritty' ~/Executables/lappie/cargo/bin rkumar@rkumarlappie:/home/rkumar/Executables/cargo
rsync -auP ~/.local/man rkumar@rkumarlappie:/home/rkumar/.local
rsync -azuP ~/.local/libexec/cni ~/.local/libexec/revokefs-fuse rkumar@rkumarlappie:/home/rkumar/.local
rsync -azuP --exclude '.local/lib/python*' ~/.local/lib rkumar@rkumarlappie:/home/rkumar/.local
rsync -auP ~/.local/share/man rkumar@rkumarlappie:/home/rkumar/.local/share
rsync -azuP --skip-compress=cmdline/search/queue ~/.local/share/newsboat rkumar@rkumarlappie:/home/rkumar/.local/share
rsync -auP ~/.local/share/buku rkumar@rkumarlappie:/home/rkumar/.local/share
rsync -azuP ~/.local/bin/fuse-overlayfs ~/.local/bin/fusermount3 rkumar@rkumarlappie:/home/rkumar/.local/bin

# vi:ft=sh


A Executables/shell-scripts/bin/share-chattiest-channels => Executables/shell-scripts/bin/share-chattiest-channels +11 -0
@@ 0,0 1,11 @@
#!/usr/bin/env dash

# save chattiest-channels to a pastebin
{
	chattiest-channels "$@"
	printf "\nIf you use weechat then you can try the script that generated this yourself: https://git.sr.ht/~seirdy/chattiest-channels"
} | curl-tor --progress -F "clbin=<-" https://clbin.com | wl-copy -n \
	&& wl-paste \
	&& curl-tor "$(wl-paste)"

# vi:ft=sh

A Executables/shell-scripts/bin/shareit => Executables/shell-scripts/bin/shareit +8 -0
@@ 0,0 1,8 @@
#!/usr/bin/env dash

# shareit: upload stdin to https://share.schollz.com.
# Generates a random filename if one is not provided.
[ -n "$1" ] && filename="$1" || filename="$(tr -dc A-Za-z0-9 </dev/urandom | head -c 10)"
curl-tor --progress --upload-file - "https://share.schollz.com/$filename" | sed 's#schollz\.com#schollz\.com/1#'

# vi:ft=sh

M Executables/shell-scripts/bin/st-cmd => Executables/shell-scripts/bin/st-cmd +1 -1
@@ 2,7 2,7 @@
# shellcheck source=/home/rkumar/Executables/shell-scripts/terminal_cmds/st-vars
. ~/Executables/shell-scripts/terminal_cmds/st-vars
export ST_CMD="st -f 'Source Code Pro for Powerline:style=Medium:pixelsize=$SIZE:antialias=true:autohint:true' -g ${ST_COLS}x${ST_ROWS}"
eval "$ST_CMD $@"
eval "$ST_CMD $*"
# if [ $# -eq 0 ]
# then
# 	eval "${ST_CMD}"

M Executables/shell-scripts/bin/start-sway => Executables/shell-scripts/bin/start-sway +1 -1
@@ 1,7 1,7 @@
#!/usr/bin/env dash

unset PROFILE_SET && export XDG_SESSION_TYPE=wayland
# shellcheck source=../../startup.sh
# shellcheck source=/home/rkumar/startup.sh
. ~/startup.sh
ssh-agent sway


M Executables/shell-scripts/bin/switch-display => Executables/shell-scripts/bin/switch-display +3 -0
@@ 1,6 1,7 @@
#!/usr/bin/env dash

new_display=$1 # Either "lap" or "mon"
# shellcheck disable=SC2154
display_cfg="$XDG_DATA_HOME/computer_state/current_display"

if [ -z "$new_display" ]; then


@@ 31,9 32,11 @@ else
fi

kdeglobals_update() {
	# shellcheck disable=SC2154
	kwriteconfig5 --file "$XDG_CONFIG_HOME/kdeglobals" "$@"
}

# shellcheck disable=SC2154
if [ "$MACHINE" = "Linux" ] && [ "$XDG_CURRENT_DESKTOP" = "KDE" ]; then
	if command -v kwriteconfig5 >/dev/null; then
		kdeglobals_update --group "General" --key "fixed" "$mono_font"

M Executables/shell-scripts/bin/terminal => Executables/shell-scripts/bin/terminal +4 -1
@@ 1,5 1,8 @@
#!/usr/bin/env dash
if [ "$XDG_SESSION_TYPE" = 'wayland' ] || [ -n "$SWAYSOCK" ] || [ -n "$WAYLAND_DISPLAY" ]; then
# shellcheck disable=SC2154
if [ "$XDG_SESSION_TYPE" = 'wayland' ] \
	|| [ -n "$SWAYSOCK" ] \
	|| [ -n "$WAYLAND_DISPLAY" ]; then
	if [ $# -gt 0 ]; then
		alacritty -e "$@"
	else

A Executables/shell-scripts/bin/unshorten => Executables/shell-scripts/bin/unshorten +6 -0
@@ 0,0 1,6 @@
#!/usr/bin/env dash

# unshorten a short URL by using the unshorten.me service
curl "https://unshorten.me/s/$1"

# vi:ft=sh

M Executables/shell-scripts/bin/update-all => Executables/shell-scripts/bin/update-all +2 -0
@@ 29,6 29,7 @@
script_dir="$HOME/Executables/shell-scripts/updates"
cd "$script_dir" || return 1
fd -t f -e sh -x chmod +x # So I can run the scripts with their shebangs
# shellcheck disable=SC2154
mkdir -p "$XDG_DATA_HOME/update-all/logs" "$GOPATH" && cd "$XDG_DATA_HOME/update-all/logs" || return 1
echo 'Compressing old logs'
fd -t d -x tar -I "lzip --best" -cf "{/}.tar.lz" "{}"


@@ 111,6 112,7 @@ if [ -z "$litemode" ]; then
	fi
fi

# shellcheck disable=SC2154
if [ "$MACHINE" = 'Linux' ]; then
	if [ -z "$litemode" ]; then
		log_bg 'stack'         # haskell packages (infrequent updates, cpu-heavy, slow)

A Executables/shell-scripts/bin/upl => Executables/shell-scripts/bin/upl +3 -0
@@ 0,0 1,3 @@
#!/usr/bin/env dash
curl-tor --progress -F"file=@$1" https://0x0.st
# vi:ft=sh

M Executables/shell-scripts/bin/url-picker => Executables/shell-scripts/bin/url-picker +1 -0
@@ 1,4 1,5 @@
#!/usr/bin/env dash
# shellcheck disable=SC2154
if [ -n "$TMUX" ]; then
	fzf_cmd='fzf-tmux'
else

M Executables/shell-scripts/bin/xdg-open => Executables/shell-scripts/bin/xdg-open +1 -0
@@ 10,6 10,7 @@ case "${1%%:*}" in
		exec aerc "$1"
		;;
	*)
		# shellcheck disable=SC2154
		case "${MACHINE}" in
			Linux)
				exec /usr/bin/xdg-open "$@"