dotfiles

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

functions (2041B)


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