dotfiles

Cross platform dotfiles for linux, mac and windows

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
[ -n "$BASH" ] && is_bash=-f

there() {
	# Checks the availability of an executable
    command -v "$@" >/dev/null 2>&1
} && export $is_bash there

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
} && export $is_bash open_project

attach() {
	command -v abduco >/dev/null || return
	if [ $# -eq 0 ]; then
		sesh_name=$(abduco -l | tail -n +2 | cut -f3 | $FUZZER)
		test -z "$sesh_name" && return
		abduco -a $sesh_name || abduco -c $sesh_name mtm;
	else
		abduco -a $1
	fi
} && export $is_bash attach

# TODO make it non-interruptable
if ! there sl; then
	sl() {
		printf "You are a noob for typing '$1'\n"; sleep 5;
	} && export $is_bash sl
fi

smartmake() {
    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'
		return
	fi

	# TODO maybe add -type in the future 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})"
	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"
		return
	fi
}

download() {
	case $1 in
		git@*|*.git|https://*.git) git clone $* ;;
		*) curl -fLO $* ;; # TODO use wget if curl not available
	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 $@
}