Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
5.0 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. #!/usr/bin/env bash
  2. # dmenu_kdeconnect.sh is a script based off of these scripts
  3. # [polybar-kdeconnect] https://github.com/HackeSta/polybar-kdeconnect
  4. # [polybar-kdeconnect-scripts] https://github.com/witty91/polybar-kdeconnect-scripts
  5. # Added features
  6. # - Removed polybar as a Dependencies (since I use dwm)
  7. # - Integration with a variety of file managers
  8. # - Implementation as one simplified shell script
  9. # - utilize sh instead of bash
  10. #TODO
  11. # 1. Allow different dmenu colors based on the battery percentage
  12. # 2. Make the script no sh complaint
  13. # 3. Implement a contacts list to make sms messaging easier
  14. # Dependancies
  15. # -dmenu
  16. # -kdeconnect
  17. # -zenity, nnn, or ranger
  18. # -qt5-tools
  19. # -dbus
  20. # -dunst
  21. # options
  22. # nnn
  23. # zenity
  24. # ranger
  25. Picker='lf'
  26. # Color Settings of dmenu
  27. COLOR_DISCONNECTED='#000' # Device Disconnected
  28. COLOR_NEWDEVICE='#ff0' # New Device
  29. COLOR_BATTERY_90='#fff' # Battery >= 90
  30. COLOR_BATTERY_80='#ccc' # Battery >= 80
  31. COLOR_BATTERY_70='#aaa' # Battery >= 70
  32. COLOR_BATTERY_60='#888' # Battery >= 60
  33. COLOR_BATTERY_50='#666' # Battery >= 50
  34. COLOR_BATTERY_LOW='#f00' # Battery < 50
  35. # Icons shown in dmenu
  36. ICON_SMARTPHONE=''
  37. ICON_TABLET=''
  38. SEPERATOR='|'
  39. DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
  40. ping -q -c 1 1.1.1.1 > /dev/null || "$(notify-send "check internet connection" && exit)"
  41. show_devices (){
  42. IFS=$','
  43. devices=""
  44. # for all the devices avalable
  45. for device in $(dbus-send --print-reply --session --dest=org.mconnect /org/mconnect/manager org.mconnect.DeviceManager.ListDevices | cut -f1 -d"[" | cut -f1 -d "]" | tail -2); do
  46. #get the device info
  47. deviceobj=$(echo "$device" | cut -f2 -d"\"" | tr -d '\n' | xargs)
  48. devicename=$(dbus-send --print-reply --session --dest=org.mconnect "$deviceobj" org.freedesktop.DBus.Properties.Get string:org.mconnect.Device string:Name | grep -E string | cut -f2 -d"\"")
  49. isreach="$(dbus-send --print-reply --session --dest=org.mconnect "$deviceobj" org.freedesktop.DBus.Properties.Get string:org.mconnect.Device string:IsConnected | grep -E boolean | cut -b 26-)"
  50. devicetype=$(dbus-send --print-reply --session --dest=org.mconnect "$deviceobj" org.freedesktop.DBus.Properties.Get string:org.mconnect.Device string:DeviceType | grep -E string | cut -f2 -d"\"")
  51. istrust="$(dbus-send --print-reply --session --dest=org.mconnect "$deviceobj" org.freedesktop.DBus.Properties.Get string:org.mconnect.Device string:Allowed | grep -E boolean | cut -b 26-)"
  52. if [ "$isreach" = "true" ] && [ "$istrust" = "true" ];then
  53. #is connected
  54. battery="$(dbus-send --print-reply --session --dest=org.mconnect $deviceobj org.freedesktop.DBus.Properties.Get string:org.mconnect.Device.Battery string:Level | grep -e uint32 | cut -b 25-)%"
  55. icon=$(get_icon $battery $devicetype)
  56. # colors="$(get_colors $battery)"
  57. # echo "$colors"
  58. show_menu "$devicename | $battery $icon" $deviceobj $battery
  59. devices+="$devicename $battery $icon $SEPERATOR"
  60. elif [ "$isreach" = "false" ] && [ "$istrust" = "true" ];then
  61. #nothing is found
  62. devices+="$(get_icon -1 $devicetype)$SEPERATOR"
  63. else
  64. #found but not yet paired
  65. icon=$(get_icon -2 $devicetype)
  66. show_pmenu $devicename $deviceobj
  67. devices+="$devicename $icon $SEPERATOR"
  68. fi
  69. done
  70. }
  71. SendKeys(){
  72. output="?"
  73. TEMPFILE=$XDG_RUNTIME_DIR/VimFloat
  74. > $TEMPFILE
  75. st -t "vim-anywhere" -n 'popup' -e "${EDITOR:-vi}" -c 'startinsert' $TEMPFILE
  76. xsel -i < $TEMPFILE
  77. output=$(xsel -o)
  78. notify-send "$output"
  79. kdeconnect-cli --device "$*" -k "$output"
  80. }
  81. #displays a menu for the connected device
  82. show_menu () {
  83. optionNum=5
  84. options=$(printf "Send SMS\\nSend File\\nSend Text\\nSend URL\\nDisconnect\\n")
  85. menu=$(echo $options | dmenu -i -p $1 -l $optionNum )
  86. case "$menu" in
  87. *'Send File')
  88. mkdir -p $XDG_RUNTIME_DIR/lf/
  89. rm -rf $XDG_RUNTIME_DIR/lf/sentfile
  90. st -c ranger -e lf -selection-path "$XDG_RUNTIME_DIR/lf/sentfile"
  91. if [ -f $XDG_RUNTIME_DIR/lf/sentfile ]; then
  92. mconnectctl share-file "$2" "$(cat $XDG_RUNTIME_DIR/lf/sentfile)"
  93. fi;;
  94. *'Send SMS' )
  95. message=$(echo 'OTW' | dmenu -i -p "Msg to send")
  96. recipient=$(echo '14039199518' | dmenu -i -p "Recipient's phone #")
  97. mconnectctl send-sms "$2" "$message" "$recipient" ;;
  98. *'Send URL' )
  99. message=$(echo 'Clipboard' | dmenu -i -p "Enter Url:")
  100. if [ "$message" = "Clipboard" ]; then
  101. message=$(sselp)
  102. fi
  103. mconnectctl share-url "$2" "$message";;
  104. *'Send Text' )
  105. message=$(echo 'Clipboard' | dmenu -i -p "Enter Text:")
  106. if [ "$message" = "Clipboard" ]; then
  107. message=$(sselp)
  108. fi
  109. mconnectctl share-text "$2" "$message";;
  110. *'Disconnect' )
  111. mconnectctl disallow-device "$2"
  112. esac
  113. }
  114. show_pmenu () {
  115. menu="$(printf "Pair Device" | dmenu -i -p "$1" )"
  116. case "$menu" in
  117. *'Pair Device') mconnectctl allow-device $2 ;;
  118. esac
  119. }
  120. get_icon () {
  121. if [ "$2" = "tablet" ]
  122. then
  123. ICON=$ICON_TABLET
  124. else
  125. ICON=$ICON_SMARTPHONE
  126. fi
  127. echo $ICON
  128. }
  129. show_devices
  130. #vim:ft=sh