: bharatvaj/dotfiles

Cross platform dotfiles for linux, mac and windows

commit c4f268e80fa28c29b804b1e724f2ef6263cbdc7a
parent 72f4f002cc06964c5a0ae7b7cd7a84dd7e94cdab
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Mon, 13 Apr 2026 01:40:02 +0530

Minimize code in aliases and functions

Change behaviour of f alias quickopen

Remove ci, in favour of inline ssh config parsing

Implement basic clip

Use 'there' in xinitrc file and move contents of keybindings into here
7 files changed, 57 insertions(+), 73 deletions(-)
D
.config/X11/keybindings
|
6
------
M
.config/X11/xinitrc
|
8
++++----
M
.config/sh/aliases
|
29
+++++++++++++++--------------
M
.config/sh/functions
|
68
+++++++++++++++++++++++++++-----------------------------------------
D
.local/bin/sh/ci
|
8
--------
M
.local/bin/sh/clip
|
10
++++++++++
M
.profile
|
1
+
diff --git a/.config/X11/keybindings b/.config/X11/keybindings
@@ -1,6 +0,0 @@
-__type() {
-    type "$@" >/dev/null 2>/dev/null
-}
-
-__type setxkbmap && setxkbmap -option caps:escape
-__type xbmap && xbmap
diff --git a/.config/X11/xinitrc b/.config/X11/xinitrc
@@ -2,10 +2,10 @@
 
 WM=dwm
 
-xrdb -merge $XDG_CONFIG_HOME/X11/Xresources
+xrdb -merge "$XDG_CONFIG_HOME/X11/Xresources"
 
-__type $WM || (echo "$WM not found" && exit 1)
-
-__type slstatus && exec slstatus &
+there $WM || (echo "$WM not found" && exit 1)
+there slstatus && exec slstatus &
+there setxkbmap -option caps:escape
 
 exec $WM
diff --git a/.config/sh/aliases b/.config/sh/aliases
@@ -1,13 +1,12 @@
 # [xdg]
-alias abook='abook --config "$XDG_CONFIG_HOME"/abook/abookrc --datafile "$XDG_DATA_HOME"/abook/addressbook'
-alias abook='abook -C "$XDG_CONFIG_HOME"/abook/abookrc --datafile "$XDG_DATA_HOME"/abook/addressbook'
+alias abook='abook -C "$XDG_CONFIG_HOME"/abook/abookrc --datafile "$XDG_DATA_HOME"/addressbook.abook'
 alias dict='dict -c "$XDG_CONFIG_HOME"/dict/dictrc'
 alias startx='startx "$XDG_CONFIG_HOME/X11/xinitrc" vt1'
 alias wget='wget --hsts-file="$XDG_CACHE_HOME/wget-hsts"'
 
 # [misc]
 # alias doas=sudo
-alias qc='ssh $(ci)'
+alias qc="ssh \"\$(sed -n -e '/\*.*/d' -e '/^Host/s/^Host //p' $XDG_HOME/.ssh/config | $FUZZER)\""
 
 # [helper_functions]
 cd_and_ls() { cd $* && ls; }

@@ -19,16 +18,17 @@ thwart lls sls lsl lss kls cdd mr
 # [ip]
 # TODO make this cross-platform
 there ifconfig && alias lip="ifconfig | grep -w inet  | cut -d ' ' -f2"
+there ip && alias lip="ip route get 1 | sed -n 's/.* src \(.*\) uid .*/\1/p'"
 there curl && alias gip="curl ifconfig.co"
+there fd || find_() { find . -name "*$**"; } && alias fd=find_
 
 # [navigation]
 alias ....='cd ../../..'
 alias ...='cd ../..'
 alias ..='cd ..'
 alias n='cd_and_ls'
-alias cf="quickopen cd d"
-alias ef="quickopen ${EDITOR} f"
-alias gf='$EDITOR $(git ls-files | ${FUZZER})'
+alias cf='quickopen "-type d" cd'
+alias ff="$EDITOR \"\$(git ls-files | $FUZZER)\""
 alias of="quickopen open f"
 if [ -n "$BASH" ] || [ -n "$ZSH_VERSION" ]; then __is_bashlike=--; fi
 alias $__is_bashlike -='cd -'

@@ -36,13 +36,11 @@ alias $__is_bashlike -='cd -'
 # [shorthands]
 alias a=attach
 alias '?d'='sr duckduckgo'
-alias cls=clear
 alias d='download'
-alias e='${EDITOR}'
-alias f=quickopen
+alias e="$EDITOR"
+alias f="quickopen \"-type f\" $EDITOR"
 alias g=git
-# TODO Use nnncd
-alias l='vifm .'
+alias l="\"$FM\" ."
 alias le=less
 alias m=smartmake
 alias x=extract.sh

@@ -51,12 +49,15 @@ there rc || alias rc='sudo systemctl'
 # [midlonghands]
 alias or='open_project ~/repo'
 alias orr='open_project ~/resrepo'
+alias op='cd "$(open_project "$HOME/repo" | $FUZZER)"'
 alias girl='grep -irl'
 alias gir='grep -ir'
 alias markdown=md2html
-alias fy='fzf | clip'
+alias fy="$FUZZER | clip"
 alias o='xdg-open'
 
-alias voom='VIM_DIR=$XDG_DATA_HOME/vim voom'
-alias dot="ln -s \"$XDG_DATA_HOME/wt/dotfiles.git\" \"$XDG_HOME/.git\""
+alias voom="VIM_PLUGINS_DIR=\"$XDG_DATA_HOME\"/vim/pack/voom/start VIM_DIR=\"$XDG_DATA_HOME\"/vim voom"
+alias nvoom="VIM_PLUGINS_DIR=\"$XDG_DATA_HOME\"/nvim/pack/voom/start VIM_DIR=\"$XDG_DATA_HOME\"/nvim voom"
+
 alias undot="rm \"$XDG_HOME/.git\""
+alias dot="ln -s \"$XDG_DATA_HOME/wt/dotfiles.git\" \"$XDG_HOME/.git\""
diff --git a/.config/sh/functions b/.config/sh/functions
@@ -2,17 +2,23 @@
 
 there() {
 	# Checks the availability of an executable
-    command -v "$@" >/dev/null 2>&1
+	command -v "$@" >/dev/null 2>&1
 } && export $is_bash there
 
 open_project() {
 	# search only dirs
+	search_loc=${1:-.}/*
+	for i in $search_loc/.git/ $search_loc/*/.git/; do
+		echo "$i.."
+	done
+} && export $is_bash open_project
+
+open_project() {
+	# search only dirs
 	search_loc=${1:-.}
-    cd "${search_loc}"
-    projdir=$(ls -d */.git | sed 's/.git$//g' | $FUZZER)
-    if [ -d "${projdir}" ]; then
-        cd "${projdir}"
-    fi
+	cd "$search_loc" || return
+	gdir="$(find . -maxdepth 2 -type d -name .git | sed 's/.git$//' | $FUZZER)"
+	cd "$gdir"
 } && export $is_bash open_project
 
 attach() {

@@ -34,38 +40,31 @@ if ! there sl; then
 fi
 
 smartmake() {
-    if there fmake && there errorformat; then
-        fmake $* | errorformat
-    else
-        make
-    fi
+	if there fmake && there errorformat; then
+		fmake $* | errorformat
+	else
+		make $*
+	fi
 } && export $is_bash smartmake
 
 quickopen() {
-	if ! there "${FUZZER}"; then
-		printf '${FUZZER} not available\n'
+	local fa ef
+	if ! there "$FUZZER"; then
+		printf '$FUZZER not available\n'
 		return
 	fi
 
-	# TODO maybe add -type in the future TODO add $name
+	# TODO add $name
 	#if [ $# -gt 0 ]; then
 	#	name="-name $@"
 	#fi
-	# 2>/dev/null
-	if [ -d .git ]; then
-		optional_files="$(git ls-files) |"
-		somethin="$(git ls-files | ${FUZZER})"
+	ef="$(find . -maxdepth 3 $fa | $FUZZER)"
+	if [ -f "$ef" ]; then
+		"${3:-$EDITOR}" "$ef"
+	elif [ -d "$ef" ]; then
+		"${3:-cd}" "$ef"
 	else
-		maxdepth=${1:-3} somethin="$(find .  -maxdepth $maxdepth | ${FUZZER})"
-	fi
-	if [ -z "$somethin" ]; then
-		return;
-	elif [ -f "$somethin" ]; then
-		$EDITOR "$somethin"
-	elif [ -d "$somethin" ]; then
-		cd "$somethin"
-	else
-		printf '%s: is neither a file nor a directory\n' "$somethin"
+		printf '%s: is neither a file nor a directory\n' "$ef"
 		return
 	fi
 }

@@ -77,16 +76,3 @@ download() {
 	esac
 }
 
-find_() {
-	find . -name "*$**"
-}
-
-vim_plug() {
-	VIM_PLUGINS_DIR="$XDG_DATA_HOME"/vim/pack/voom/opt \
-		VIM_DIR="$XDG_DATA_HOME"/vim voom $@
-}
-
-nvim_plug() {
-    VIM_PLUGINS_DIR="$XDG_DATA_HOME"/nvim/pack/voom/optj \
-    	VIM_DIR="$XDG_DATA_HOME"/nvim voom $@
-}
diff --git a/.local/bin/sh/ci b/.local/bin/sh/ci
@@ -1,8 +0,0 @@
-#!/bin/sh
-# ci - computer index
-
-s_db="$XDG_DATA_HOME/personal/systems.json"
-
-s_system=$(jq -r 'keys[]' "$s_db" | fzf)
-s_addr=$(jq -r ".$s_system" "$s_db")
-echo $s_addr
diff --git a/.local/bin/sh/clip b/.local/bin/sh/clip
@@ -2,3 +2,13 @@
 
 # TODO cross-platform clipborad
 # Use OS-specific, should work both on console and X
+os="$(uname -s)"
+if [ "$os" = "Darwin" ]; then
+    pbcopy
+elif [ "$os" = "Windows_NT" ]; then
+    command clip
+elif command -v xclip >/dev/null; then
+    xclip
+elif command -v xsel >/dev/null; then
+    xclip
+fi
diff --git a/.profile b/.profile
@@ -48,6 +48,7 @@ if [ "$(uname -s)" = "Windows_NT" ]; then
 else
     FUZZER=fzy
 fi
+# TODO Use nnncd
 FM=vifm
 
 BROWSER=lynx