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.

134 lines
4.7 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
  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. source ~/.config/config.env
  41. show_devices (){
  42. device=$(mconnectctl | grep $MCONNECT_DEVICE | sed 's/\s\{2,\}/\n/g; s/ - /\n/g;s/^\n//g' | head -n 1)
  43. deviceobj=$(echo "$device" | cut -f2 -d"\"" | tr -d '\n' | xargs)
  44. 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"\"")
  45. 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-)"
  46. 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"\"")
  47. 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-)"
  48. if [ "$isreach" = "true" ] && [ "$istrust" = "true" ];then
  49. #is connected
  50. 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-)%"
  51. icon=$(get_icon $battery $devicetype)
  52. # colors="$(get_colors $battery)"
  53. # echo "$colors"
  54. show_menu "$devicename | $battery $icon" $deviceobj $battery
  55. devices+="$devicename $battery $icon $SEPERATOR"
  56. elif [ "$isreach" = "false" ] && [ "$istrust" = "true" ];then
  57. #nothing is found
  58. devices+="$(get_icon -1 $devicetype)$SEPERATOR"
  59. else
  60. #found but not yet paired
  61. icon=$(get_icon -2 $devicetype)
  62. show_pmenu $devicename $deviceobj
  63. devices+="$devicename $icon $SEPERATOR"
  64. fi
  65. }
  66. SendKeys(){
  67. output="?"
  68. TEMPFILE=$XDG_RUNTIME_DIR/VimFloat
  69. > $TEMPFILE
  70. st -t "vim-anywhere" -n 'popup' -e "${EDITOR:-vi}" -c 'startinsert' $TEMPFILE
  71. xsel -i < $TEMPFILE
  72. output=$(xsel -o)
  73. notify-send "$output"
  74. kdeconnect-cli --device "$*" -k "$output"
  75. }
  76. #displays a menu for the connected device
  77. show_menu () {
  78. optionNum=5
  79. options="Send SMS\nSend File\nSend Text\nSend URL\nDisconnect\n"
  80. menu=$(printf "$options" | dmenu -i -p "$1" -l $optionNum )
  81. case "$menu" in
  82. *'Send File')
  83. mkdir -p $XDG_RUNTIME_DIR/lf/
  84. rm -rf $XDG_RUNTIME_DIR/lf/sentfile
  85. st -c ranger -e lf-ueberzug -selection-path "$XDG_RUNTIME_DIR/lf/sentfile"
  86. if [ -f $XDG_RUNTIME_DIR/lf/sentfile ]; then
  87. mconnectctl share-file "$2" "$(cat $XDG_RUNTIME_DIR/lf/sentfile)"
  88. fi;;
  89. *'Send SMS' )
  90. message=$(echo 'OTW' | dmenu -i -p "Msg to send")
  91. recipient=$(echo '14039199518' | dmenu -i -p "Recipient's phone #")
  92. mconnectctl send-sms "$2" "$message" "$recipient" ;;
  93. *'Send URL' )
  94. message=$(dmenu -i -p "Enter Url:" < /dev/null)
  95. if [ "$message" = "Clipboard" ]; then
  96. message=$(sselp)
  97. fi
  98. mconnectctl share-url "$2" "$message";;
  99. *'Send Text' )
  100. message=$(dmenu -i -p "Enter Text:" < /dev/null)
  101. mconnectctl share-text "$2" "$message";;
  102. *'Disconnect' )
  103. mconnectctl disallow-device "$2"
  104. esac
  105. }
  106. show_pmenu () {
  107. menu="$(printf "Pair Device" | dmenu -i -p "$1" )"
  108. case "$menu" in
  109. *'Pair Device') mconnectctl allow-device $2 ;;
  110. esac
  111. }
  112. get_icon () {
  113. if [ "$2" = "tablet" ]
  114. then
  115. ICON=$ICON_TABLET
  116. else
  117. ICON=$ICON_SMARTPHONE
  118. fi
  119. echo $ICON
  120. }
  121. show_devices
  122. #vim:ft=sh