dnavigate

menu tree tool for dmenu
git clone git://git.girlpoison.org/dnavigate
Log | Files | Refs | README | LICENSE

dialer (1958B)


      1 #!/bin/bash
      2 OPTIONS="$OPTIONS -noi"
      3 TERMEXEC="urxvt -e"
      4 
      5 DIAL_HOSTS=("host.example
      6 		alice:/home/alice/:$HOME/net/host.example/home 
      7 		git:srv:$HOME/net/host.example/git
      8 		root"
      9 		"host2.example
     10 		bob")
     11 SSHFS_OPTS="-o idmap=user"
     12 XCLIP=1
     13 
     14 B=$1; shift;
     15 case $B in
     16 main)
     17 	PROMPT="dial"
     18 
     19 	for H in "${DIAL_HOSTS[@]}"; do
     20 		HOST=$(echo $H | awk '$0=$1')
     21 		USERS=$(echo $H | awk '$1="";1')
     22 
     23 		LEAVES[${#LEAVES[*]}]="$HOST"
     24 		ACTIONS[${#ACTIONS[*]}]="run $TERMEXEC abduco -c '$HOST.$$' ssh $HOST"
     25 		for U in $USERS; do
     26 			USER="$(echo "$U" | cut -d: -f1)"
     27 			if echo "$U" | grep ':' >/dev/null; then
     28 				MOUNT="$(echo "$U" | cut -d: -f2-)"
     29 				if [ "$USER" = "$PREV" ]; then
     30 					P=$((${#ACTIONS[*]}-1))
     31 					ACTIONS[$P]="${ACTIONS[$P]} '$MOUNT'"
     32 				else
     33 					LEAVES[${#LEAVES[*]}]="   user: $USER...";
     34 					ACTIONS[${#ACTIONS[*]}]="child connect $USER $HOST '$MOUNT'"
     35 				fi
     36 			else
     37 				LEAVES[${#LEAVES[*]}]="   user: $USER";
     38 				ACTIONS[${#ACTIONS[*]}]="run $TERMEXEC abduco -c '$HOST.$$' ssh $USER@$HOST"
     39 			fi
     40 			PREV="$USER"
     41 		done
     42 	done;;
     43 connect)
     44 	USER="$1"; HOST="$2"; shift 2
     45 	PROMPT="$USER@$HOST"
     46 	
     47 	LEAVES=("connect")
     48 	ACTIONS=("run $TERMEXEC abduco -c '$HOST.$$' ssh $USER@$HOST")
     49 
     50 	[ "$*" ] || break;
     51 
     52 	LEAVES[${#LEAVES[*]}]=""
     53 	ACTIONS[${#ACTIONS[*]}]="back"
     54 	while [ "$*" ]; do
     55 		REMOTE="$(echo $1 | cut -d: -f1)"
     56 		LOCAL="$(echo $1 | cut -d: -f2-)"
     57 		[ "$LOCAL" ] || panic "$TREE/$BRANCH: missing LOCAL in mount declaration for '$USER@$HOST'"
     58 		MOUNTED="$(awk -v d="$USER@$HOST:$REMOTE" '$1==d && $3=="fuse.sshfs" {print $2}' </etc/mtab)"
     59 		if [ "$MOUNTED" ]; then
     60 			LEAVES[${#LEAVES[*]}]="unmount: $REMOTE"
     61 			ACTIONS[${#ACTIONS[*]}]="fusermount3 -u $LOCAL"
     62 		else
     63 			LEAVES[${#LEAVES[*]}]="mount: ${REMOTE:-~}"
     64 			ACTIONS[${#ACTIONS[*]}]="mount $USER $HOST '$REMOTE' '$LOCAL'"
     65 		fi
     66 		shift 1;
     67 	done
     68 	;;
     69 esac
     70 
     71 mount() {
     72 	[ -d "$LOCAL" ] || mkdir -p "$LOCAL"
     73 	sshfs "$1@$2:$3" "$4" $SSHFS_OPTS || exit 1;
     74 	[ "$XCLIP" ] && echo "$4" | xclip -r
     75 }