the_earnest/dotfiles

initial commit

Commit e35ea7816fe6 · The Earnest · 2026-11-18 16:55 +0000

Changeset
e35ea7816fe699acbd3714c3cbd316f0e56995ed

View source at this commit

Comments

No comments yet.

Log in to comment

Diff

diff --git a/bashrc b/bashrc
new file mode 100644
--- /dev/null
+++ b/bashrc
@@ -0,0 +1,295 @@
+set -o vi
+
+shopt -s cdspell
+shopt -s globstar
+shopt -s autocd
+
+alias c='cp -vi'
+alias m='mv -vi'
+alias r='rm -vi'
+
+alias h=history
+alias l='ls --color=auto -g -G --group-directories-first -r -t'
+alias lh='ls --color=auto -g -G --group-directories-first -r -t -h'
+alias l1="ls --color=auto -1"
+
+alias v='vim'
+
+alias u='cd ..'
+alias uu='cd ../..'
+alias uuu='cd ../../..'
+alias uuuu='cd ../../../..'
+alias uuuuu='cd ../../../../..'
+
+alias yd='yt-dlp'
+alias ydv='yt-dlp -f 18'
+alias ydlq='yt-dlp -f 160+140'
+alias ydlq2='yt-dlp -f 160+249'
+alias ydmq='yt-dlp -f 134+249'
+alias yda='yt-dlp -f 140'
+alias ydF='yt-dlp -F'
+alias ydb='yt-dlp -f bv+140'
+alias ydS='yt-dlp -S "+height:360"'
+
+alias sdc='cd ~/storage/sdcard'
+alias sdo='cd ~/storage/downloads'
+alias sdr='cd ~/storage/shared'
+
+alias sbrc='source ~/.bashrc'
+alias vbrc='vim ~/.bashrc'
+
+alias rdfind_hard='rdfind -deleteduplicates true'
+alias findduplicates=rdfind
+alias find_duplicates=rdfind
+
+alias ffmpegnb='ffmpeg -hide_banner'
+alias ffprobenb='ffprobe -hide_banner'
+alias ffprobe_getresolution='ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0'
+alias ffprobe_getduration='ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 -sexagesimal'
+
+# recursive, (case) insensitive grep
+function rigrep {
+	if [[ $# -ne 2 ]]; then
+		echo $0: error - expected 2 arguments, found $#
+		return
+	fi
+	FINDCMD="find -iname '*"
+	FINDCMD+="$2"
+	FINDCMD+="*' -print0 | "
+	FINDCMD+="xargs -0 grep -i '"
+	FINDCMD+="$1"
+	FINDCMD+="'"
+	#echo FINDCMD=$FINDCMD
+	eval "$FINDCMD"
+}
+
+function rm_empty_dirs {
+	find -mindepth 1 -maxdepth 1 -type d -print0 | xargs -0 rmdir --ignore-fail-on-non-empty
+}
+
+# func to invoke rm, with log of removed files
+function delete {
+	if [[ $# -lt 1 ]]; then
+		echo "error: expected one or more arguments (file names) but found none"
+		return
+	fi
+	local DELETE_LOG=delete.log
+	local DELETE_ERR=delete.err
+	if [[ ! -e "$DELETE_LOG" ]]
+	then
+		touch "$DELETE_LOG"
+	fi
+	if [[ ! -w "$DELETE_LOG" ]]
+	then
+		echo "error: Cannot write logfile; aborting without removals."
+		return
+	fi
+	# move the log because it mayunintentionally be among the
+	# filenames given as arguments; this could be due to expansion
+	# of '*' for example
+	mv "$DELETE_LOG" "$TMPDIR"
+	# now perform the actual removal
+	rm -v "$@" 2>"$DELETE_ERR" | tee -a "$TMPDIR/$DELETE_LOG"
+	if [[ -e "$DELETE_ERR" ]]
+	then
+		# show errors but filter out the (possible) line about the
+		# logfile itself
+		grep -v "rm: cannot remove '$DELETE_LOG'" "$DELETE_ERR"
+		rm "$DELETE_ERR"
+	fi
+	# move the logfile back
+	mv "$TMPDIR/$DELETE_LOG" .
+	#echo "Succesful deletions logged in '$DELETE_LOG'"
+}
+
+function fgall {
+	JOBNUMS=$(jobs | sed -n -e \
+		'/\[\([0-9]\+\)\]/{s/.*\[\([0-9]\+\)\].*/\1/;p}')
+	[[ -z "$JOBNUMS" ]] && echo "No jobs."
+	for i in $JOBNUMS; do
+		fg %$i
+	done
+}
+
+function mcd {
+	if [[ $# -ne 1 ]]; then
+		echo ERROR: expected 1 argument, found $#. Add quotemarks if you want \"$@\" treated as a single argument.
+		return
+	fi
+	if [[ -d "$1" ]]; then
+		echo "Directory exists; cd'ing into."
+	elif [[ -e "$1" ]]; then
+		echo "ERROR: A non-directory by that name already exists; cannot mkdir."
+		return
+	else
+		mkdir -p "$1"
+		echo "Created directory '$1'."
+	fi
+	cd "$1"
+}
+
+function flatten_this_epub_dir {
+	find -iname 'metadata.opf' -delete
+	find -iname '*.jpg' -delete
+	find -iname '*.txt' -delete
+	find -iname '*.opf' -delete
+	find -type f -exec mv -vn {} . \;
+	rmdir --ignore-fail-on-non-empty */
+}
+
+function stats {
+	FMT="%n (%F, %s bytes)\n  m=%y\n  c=%z\n"
+	#SUB1='s/=\(....\)-\(..\)-\(..\) /=\3\/\2\/\1/ '
+  SUB1='s/=....-..-.. /=/'
+	SUB2='s/\.......... +..00//'
+	if [[ $# -eq 0 ]]
+	then
+		stat --printf "$FMT" * | sed -e "$SUB1" -e "$SUB2"
+	else
+		stat --printf "$FMT" "$@" | sed -e "$SUB1" -e "$SUB2"
+	fi
+}
+
+function vcd() {
+	RANGER=$(which ranger)
+	if [[ -z "$RANGER" ]]
+	then
+		echo "error: ranger not found"
+		return
+	fi
+	TMPFILE="$TMPDIR/ranger.tmp"
+  "$RANGER" --choosedir="$TMPFILE" --show-only-dirs
+  TARGET_DIR=$(cat "$TMPFILE")
+	cd "$TARGET_DIR"
+	rm "$TMPFILE"
+}
+
+source ~/hg/godir/godir.bash
+source ~/hg/scripts/ffcut.bash
+
+INIT_DIR=storage/downloads
+[[ -d "$INIT_DIR" ]] && cd "$INIT_DIR" 
+
+PS1='\[\e[0;32m\]\w\[\e[0m\] \[\e[0;97m\]\n\$\[\e[0m\] '
+
+# append ~/bin to PATH if it's not already in PATH
+#ZZ=$(echo $PATH | grep -o ~/bin)
+#[[ -z "$ZZ" ]] && PATH=$PATH:~/bin
+if [[ ! "$PATH" =~ "$HOME/bin" ]]; then
+  PATH=$PATH:~/bin
+fi
+
+function seen()
+{
+	if [[ $# -lt 1 ]]; then
+		echo error: Expected 1 or more arguments, found $#
+		return
+	fi
+	[[ ! -d "seen" ]] && mkdir -p "seen"
+	mv -v -t "seen" "$@"
+}
+
+function safermdir()
+{
+	if [[ $# -ne 1 ]]; then
+		echo error: Expected 1 argument, found $#
+		return
+	fi
+	[[ ! -e "$1" ]] && echo "error: '$1' does not exist" && return
+	[[ ! -d "$1" ]] && echo "error: '$1' is not a directory" && return
+	du -sh "$1"
+	local N=$(find "$1" -type f | wc -l)
+	echo "contains $N files"
+	confirm
+	if [[ $? -eq 1 ]]; then
+		rm -rfv "$1"
+	else
+		echo "Aborted, nothing removed."
+	fi
+}	
+
+function confirm()
+{
+	read -p "Are you sure? " input
+	case "$input" in
+		y|Y|yes|YES ) return 1;;
+	esac
+	return 0
+}
+
+function ffreenc()
+{
+	#if [[ $# -ne 3 ]]; then
+	#	echo error: Expected 3 arguments, found $#
+	#	echo usage: ffreenc filename vres crf
+	#	return
+	#fi
+	#if [[ "$2" -lt 240 ]]; then
+	#	echo "error: vres value $2 is unreasonably low; set it to 240 or more"
+	#	return
+	#fi
+	#if [[ "$3" -lt 17 ]]; then
+	#	echo "error: crf value $3 is unreasonably low; set it to 17 or more"
+	#	return
+	#fi
+	#ffmpeg -hide_banner -i "$1" -c:a libopus -b:a 48k -vf scale=-2:"$2" -c:v libx264 -preset veryfast -tune film -crf "$3" ffreenc.mp4
+	ffreenc_video "$@"
+	ffreenc_audio "$1"
+}
+
+function ffreenc_audio()
+{
+	if [[ $# -ne 1 ]]; then
+		echo error: Expected 1 argument, found $#
+		echo usage: ffreenc filename 
+		return
+	fi
+	ffmpeg -hide_banner -i "$1" -vn -ac 2 -c:a libopus -b:a 48k "audio_48k.opus"
+}
+
+function ffreenc_video()
+{
+	if [[ $# -ne 3 ]]; then
+		echo error: Expected 3 arguments, found $#
+		echo usage: ffmpeg_ffreenc filename vres crf
+		return
+	fi
+	if [[ "$2" -lt 240 ]]; then
+		echo "error: vres value $2 is unreasonably low; set it to 240 or more"
+		return
+	fi
+	if [[ "$3" -lt 17 ]]; then
+		echo "error: crf value $3 is unreasonably low; set it to 17 or more"
+		return
+	fi
+	ffmpeg -hide_banner -i "$1" -an -vf scale=-2:"$2" -c:v libx264 -preset veryfast -tune film -crf "$3" "video_${2}p_crf$3.mp4"
+}
+
+function ffreenc_combine()
+{
+	ffmpeg -hide_banner -i "$1" -i "$2" -map 0:v -map 1:a -c copy combo.mp4
+}
+
+function extract_aac_from_mp4() {
+	if [[ $# -lt 1 ]]; then
+		echo error: Expected 1 or more arguments, found $#
+		return
+	fi
+	for i in "$@"
+	do
+		echo "$i" 
+    ffmpeg -hide_banner -loglevel error -i "$i" -c:a copy "${i%.mp4}.aac"
+		if [[ $? -ne 0 ]]
+		then
+			echo ERROR
+		else
+			echo OK
+		fi
+  done
+}
+
+# convenient values
+YOUTUBE='https://www.youtube.com/watch?v'
+
+# show reminder file if present
+[ -e ~/reminders.txt ] && cat ~/reminders.txt	
diff --git a/vimrc b/vimrc
new file mode 100644
--- /dev/null
+++ b/vimrc
@@ -0,0 +1,28 @@
+se hidden
+se nonumber
+
+se noincsearch
+se hlsearch
+se ignorecase
+se smartcase
+
+se ts=2
+se noet
+se sw=2
+se tw=66
+se autoindent
+
+nnoremap j gj
+nnoremap k gk
+nnoremap <Space> :nohlsearch<CR>
+
+let mapleader = ","
+"nnoremap <Leader>i i<i><Esc>
+"nnoremap <Leader>j a</i><Esc>
+
+" Return to last edit position when opening files 
+autocmd BufReadPost *
+     \ if line("'\"") > 0 && line("'\"") <= line("$") |
+     \   exe "normal! g`\"" |
+     \ endif
+