dotfiles

Cross platform dotfiles for linux, mac and windows
git clone git@nonplanar.org:dotfiles.git
Log | Files | Refs

functions (1899B)


      1 [ -n "$BASH" ] && is_bash=-f
      2 
      3 there() {
      4 	# Checks the availability of an executable
      5     command -v "$@" >/dev/null 2>&1
      6 } && export $is_bash there
      7 
      8 open_project() {
      9 	# search only dirs
     10 	search_loc=${1:-.}/*
     11 	for i in $search_loc/.git/ $search_loc/*/.git/; do
     12 		echo "$i.."
     13 	done
     14 } && export $is_bash open_project
     15 
     16 attach() {
     17 	command -v abduco >/dev/null || return
     18 	if [ $# -eq 0 ]; then
     19 		sesh_name=$(abduco -l | tail -n +2 | cut -f3 | $FUZZER)
     20 		test -z "$sesh_name" && return
     21 		abduco -a $sesh_name || abduco -c $sesh_name mtm;
     22 	else
     23 		abduco -a $1
     24 	fi
     25 } && export $is_bash attach
     26 
     27 # TODO make it non-interruptable
     28 if ! there sl; then
     29 	sl() {
     30 		printf "You are a noob for typing '$1'\n"; sleep 5;
     31 	} && export $is_bash sl
     32 fi
     33 
     34 smartmake() {
     35     if there fmake && there errorformat; then
     36         fmake $* | errorformat
     37     else
     38         make
     39     fi
     40 } && export $is_bash smartmake
     41 
     42 quickopen() {
     43 	if ! there "${FUZZER}"; then
     44 		printf '${FUZZER} not available\n'
     45 		return
     46 	fi
     47 
     48 	# TODO maybe add -type in the future TODO add $name
     49 	#if [ $# -gt 0 ]; then
     50 	#	name="-name $@"
     51 	#fi
     52 	# 2>/dev/null
     53 	if [ -d .git ]; then
     54 		optional_files="$(git ls-files) |"
     55 		somethin="$(git ls-files | ${FUZZER})"
     56 	else
     57 		maxdepth=${1:-3} somethin="$(find .  -maxdepth $maxdepth | ${FUZZER})"
     58 	fi
     59 	if [ -z "$somethin" ]; then
     60 		return;
     61 	elif [ -f "$somethin" ]; then
     62 		$EDITOR "$somethin"
     63 	elif [ -d "$somethin" ]; then
     64 		cd "$somethin"
     65 	else
     66 		printf '%s: is neither a file nor a directory\n' "$somethin"
     67 		return
     68 	fi
     69 }
     70 
     71 download() {
     72 	case $1 in
     73 		git@*|*.git|https://*.git) git clone $* ;;
     74 		*) curl -fLO $* ;; # TODO use wget if curl not available
     75 	esac
     76 }
     77 
     78 find_() {
     79 	find . -name "*$**"
     80 }
     81 
     82 vim_plug() {
     83 	VIM_PLUGINS_DIR="$XDG_DATA_HOME"/vim/pack/voom/opt \
     84 		VIM_DIR="$XDG_DATA_HOME"/vim voom $@
     85 }
     86 
     87 nvim_plug() {
     88     VIM_PLUGINS_DIR="$XDG_DATA_HOME"/nvim/pack/voom/optj \
     89     	VIM_DIR="$XDG_DATA_HOME"/nvim voom $@
     90 }