Browse Source

I love this

main
Yiğit Çolakoğlu 4 years ago
parent
commit
3e28dc56fc
7 changed files with 198 additions and 6 deletions
  1. +1
    -1
      config.env.def
  2. +150
    -0
      scripts/dmenu-mconnect
  3. +39
    -0
      scripts/status-bar/mconnect
  4. +2
    -3
      suckless/dwmblocks/config.h
  5. +1
    -1
      suckless/dwmblocks/dwmblocks.c
  6. +1
    -0
      xorg/xinitrc
  7. +4
    -1
      zsh/aliases

+ 1
- 1
config.env.def View File

@ -8,4 +8,4 @@ export TEMP_ZONE=/sys/class/thermal/thermal_zone0/temp
export NO_BAT=true
export NEXTCLOUD=false
export MCONNECT=true
export MCONNECT_DEVICE=/org/mconnect/device/0

+ 150
- 0
scripts/dmenu-mconnect View File

@ -0,0 +1,150 @@
#!/usr/bin/env bash
# dmenu_kdeconnect.sh is a script based off of these scripts
# [polybar-kdeconnect] https://github.com/HackeSta/polybar-kdeconnect
# [polybar-kdeconnect-scripts] https://github.com/witty91/polybar-kdeconnect-scripts
# Added features
# - Removed polybar as a Dependencies (since I use dwm)
# - Integration with a variety of file managers
# - Implementation as one simplified shell script
# - utilize sh instead of bash
#TODO
# 1. Allow different dmenu colors based on the battery percentage
# 2. Make the script no sh complaint
# 3. Implement a contacts list to make sms messaging easier
# Dependancies
# -dmenu
# -kdeconnect
# -zenity, nnn, or ranger
# -qt5-tools
# -dbus
# -dunst
# options
# nnn
# zenity
# ranger
Picker='zenity'
# Color Settings of dmenu
COLOR_DISCONNECTED='#000' # Device Disconnected
COLOR_NEWDEVICE='#ff0' # New Device
COLOR_BATTERY_90='#fff' # Battery >= 90
COLOR_BATTERY_80='#ccc' # Battery >= 80
COLOR_BATTERY_70='#aaa' # Battery >= 70
COLOR_BATTERY_60='#888' # Battery >= 60
COLOR_BATTERY_50='#666' # Battery >= 50
COLOR_BATTERY_LOW='#f00' # Battery < 50
# Icons shown in dmenu
ICON_SMARTPHONE=''
ICON_TABLET=''
SEPERATOR='|'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
ping -q -c 1 1.1.1.1 > /dev/null || "$(notify-send "check internet connection" && exit)"
show_devices (){
IFS=$','
devices=""
# for all the devices avalable
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
#get the device info
deviceobj=$(echo "$device" | cut -f2 -d"\"" | tr -d '\n' | xargs)
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"\"")
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-)"
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"\"")
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-)"
if [ "$isreach" = "true" ] && [ "$istrust" = "true" ];then
#is connected
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-)%"
icon=$(get_icon $battery $devicetype)
# colors="$(get_colors $battery)"
# echo "$colors"
show_menu "$devicename | $battery $icon" $deviceid $battery
devices+="$devicename $battery $icon $SEPERATOR"
elif [ "$isreach" = "false" ] && [ "$istrust" = "true" ];then
#nothing is found
devices+="$(get_icon -1 $devicetype)$SEPERATOR"
else
#found but not yet paired
icon=$(get_icon -2 $devicetype)
show_pmenu $devicename $deviceid
devices+="$devicename $icon $SEPERATOR"
fi
done
}
SendKeys(){
output="?"
TEMPFILE=/tmp/VimFloat
> $TEMPFILE
st -t "vim-anywhere" -n 'popup' -e "${EDITOR:-vi}" -c 'startinsert' $TEMPFILE
xsel -i < $TEMPFILE
output=$(xsel -o)
notify-send "$output"
kdeconnect-cli --device "$*" -k "$output"
}
#displays a menu for the connected device
show_menu () {
optionNum=5
options=$(printf "Send SMS\\nSend File\\nFind Device\\nPing\\nUnpair\\nkeys\\n")
options+=$(printf "\\nRefresh\\n")
menu=$(echo $options | dmenu -i -p $1 -l $optionNum )
case "$menu" in
*'Send File')
[ $Picker == 'nnn' ] && kdeconnect-cli --share "file://$($TERMINAL nnn -p -)" -d $2 ;
[ $Picker == 'zenity' ] && kdeconnect-cli --share "file://$(zenity --file-selection)" -d $2 ;
if [ $Picker == 'ranger' ]; then
mkdir -p /tmp/ranger/ && touch /tmp/ranger/sentfile
kdeconnect-cli --share "file://$($TERMINAL ranger --choosefile=/tmp/ranger/sentfile)" -d $2
fi;;
*'Unpair' ) kdeconnect-cli --unpair -d $2 ;;
*'Send SMS' )
message=$(echo 'OTW' | dmenu -i -p "Msg to send")
recipient=$(echo '14039199518' | dmenu -i -p "Recipient's phone #")
kdeconnect-cli --send-sms "$message" --destination "$recipient" -d $2 ;;
*'Refresh' )
kdeconnect-cli --refresh;;
*'Notification' )
Notification_menu $notification1 $2;;
*'keys' )
SendKeys "$2";;
esac
}
show_pmenu () {
menu="$(printf "Pair Device" | dmenu -i -p "$1" )"
case "$menu" in
*'Pair Device') kdeconnect-cli --pair -d $2 ;;
esac
}
#still a work in progress
# get_colors () {
# case $1 in
# "-1") colors="-nb \"$COLOR_DISCONNECTED\" -nf \"#000\" " ;;
# "-2") colors="-nb \"$COLOR_NEWDEVICE\" -nf \"#000\" ";;
# 5*) colors="-nb \"$COLOR_BATTERY_50\" -nf \"#000\" ";;
# 6*) colors="-nb \"$COLOR_BATTERY_60\" -nf \"#000\" ";;
# 7*) colors="-nb \"$COLOR_BATTERY_70\" -nf \"#000\" ";;
# 8*) colors="-nb \"$COLOR_BATTERY_80\" -nf \"#000\" ";;
# *) colors="-nb \"$COLOR_BATTERY_LOW\" -nf \"#000\" ";;
# 9*|100) colors="-nb \"$COLOR_BATTERY_90\" -nf \"#000\" ";;
# esac
# echo $colors
# }
get_icon () {
if [ "$2" = "tablet" ]
then
ICON=$ICON_TABLET
else
ICON=$ICON_SMARTPHONE
fi
echo $ICON
}
show_devices
#vim:ft=sh

+ 39
- 0
scripts/status-bar/mconnect View File

@ -0,0 +1,39 @@
#!/bin/bash
source ~/.config.env
if [ ! "$MCONNECT" = true ] ; then
echo "^c#EBCB8B^ ^d^"
exit 0
fi
device_status=$(mconnectctl show-device $MCONNECT_DEVICE)
IFS=$'\n'
lines=($device_status)
IFS=": "
read -ra connected <<< ${lines[8]}
connected=${connected[1]}
if [ ! "$connected" = true ] ; then
echo "^c#EBCB8B^ ^d^"
exit 0
fi
battery_status=$(mconnectctl show-battery $MCONNECT_DEVICE)
IFS=$'\n'
lines=($battery_status)
IFS=": "
read -ra level <<< ${lines[0]}
level=${level[1]}
read -ra charging <<< ${lines[1]}
charging=${charging[1]}
if [ "$charging" = 1 ] ; then
echo "^c#EBCB8B^ ^d^ $level%+"
else
echo "^c#EBCB8B^ ^d^ $level%"
fi

+ 2
- 3
suckless/dwmblocks/config.h View File

@ -2,14 +2,13 @@
#define PATH(name) "/home/yigit/.scripts/status-bar/"name
static Block blocks[] = {
// { "", PATH("clipboard"), 30, 18},
{ "", PATH("screensaver"), 120, 19},
{ "", PATH("dunst"), 120, 18},
{ "", PATH("mconnect"), 120, 20},
{ "", PATH("cpu-temp"), 30, 17},
{ "", PATH("weather"), 60, 16},
{ "", PATH("arch"), 120, 15},
{ "", PATH("volume"), 120, 14},
{ "", PATH("volume"), 5, 14},
{ "", PATH("network"), 120, 13},
{ "", PATH("battery"), 60, 12},
{ "", PATH("time"), 30, 11},


+ 1
- 1
suckless/dwmblocks/dwmblocks.c View File

@ -36,7 +36,7 @@ static Display *dpy;
static int screen;
static Window root;
static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0};
static char statusstr[2][256];
static char statusstr[2][512];
static int statusContinue = 1;
static void (*writestatus) () = setroot;


+ 1
- 0
xorg/xinitrc View File

@ -58,6 +58,7 @@ dbus-update-activation-environment --systemd DISPLAY
picom --no-fading-openclose &
firefox-developer-edition app.daily.dev&
bitwarden-desktop &
curl 'http://yeetclock/setcolor?R=136&G=192&B=208' &
~/.keyboard
#thunderbird &


+ 4
- 1
zsh/aliases View File

@ -4,7 +4,6 @@ alias feh="feh --scale-down --auto-zoom"
alias clear="clear && neofetch --ascii ~/.config/neofetch/ascii.txt"
alias neofetch="neofetch --ascii ~/.config/neofetch/ascii.txt"
alias idea="/home/yigit/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/201.7223.91/bin/idea.sh"
alias lights_off="curl 'http://yeetclock/setcolor?R=2000&G=10&B=000&O=0'"
alias open=xdg-open
alias rm="rm -i"
alias clip="xclip -selection clipboard"
@ -18,3 +17,7 @@ alias ls="ls --color"
# Suffix aliases
alias -g G=" | rg"
alias gshh="gcloud cloud-shell ssh --authorize-session"
# YeetClock
alias light="curl 'http://yeetclock/setcolor?R=136&G=192&B=208'"
alias lights_off="curl 'http://yeetclock/setcolor?R=2000&G=10&B=000&O=0'"

Loading…
Cancel
Save