Back (Current repo: dotfiles)

my dotfiles to make it easy to transfer my settings
To clone this repository:
git clone https://git.viktor1993.net/dotfiles.git
Log | Download | Files | Refs

connectphone (1000B)


#!/bin/bash

#a simple script for connecting my android phone with jmtpfs for file transfers via dmenu

function connect_android() {
    CONNECTION_EXISTS=$(grep -c "jmtpfs" /etc/mtab)
    if [[ $CONNECTION_EXISTS -eq 0 ]]; then
        mkdir -p /tmp/jmtpfs/android && jmtpfs /tmp/jmtpfs/android && notify-send "Device connected."
    else
        notify-send "Device already connected, or previous disconnect not cleaned up."
    fi
}

function disconnect_android() {

    FOLDER_EXISTS=$(ls /tmp | grep -c "jmtpfs")

    if [[ $FOLDER_EXISTS -eq 1 ]]; then
        lsof /tmp/jmtpfs/android  | awk '(NR>1){print $2}' | xargs -I {} kill -9 {} #kill any processes before attempting to unmount
        fusermount -u /tmp/jmtpfs/android && rm -rf /tmp/jmtpfs && notify-send "Device disconnected."
    fi

}

OPTSTRING=":cd"

while getopts ${OPTSTRING} opt; do
      case ${opt} in
              c) connect_android ;;
              d) disconnect_android ;;
              *) exit 1 ;;
          esac
done