From c299a791b70887ed2557ee11805cd577eb26068b Mon Sep 17 00:00:00 2001 From: Dmitry Fedotov Date: Thu, 26 Mar 2020 17:10:23 +0300 Subject: [PATCH] Added scripts. Modified .bash_profile. --- scripts/cpu-temp.sh | 3 +++ scripts/dmenumount.sh | 20 ++++++++++++++++++++ scripts/idea-reset.sh | 14 ++++++++++++++ scripts/iface.sh | 24 ++++++++++++++++++++++++ scripts/key-map.sh | 3 +++ scripts/keymap-switch.sh | 4 ++++ scripts/mem.sh | 25 +++++++++++++++++++++++++ scripts/screen-locker.sh | 13 +++++++++++++ scripts/shutdown.sh | 14 ++++++++++++++ scripts/volume.sh | 27 +++++++++++++++++++++++++++ scripts/wallpaper.sh | 14 ++++++++++++++ shell/.bash_profile.symlink | 1 + 12 files changed, 162 insertions(+) create mode 100755 scripts/cpu-temp.sh create mode 100755 scripts/dmenumount.sh create mode 100755 scripts/idea-reset.sh create mode 100755 scripts/iface.sh create mode 100755 scripts/key-map.sh create mode 100755 scripts/keymap-switch.sh create mode 100755 scripts/mem.sh create mode 100755 scripts/screen-locker.sh create mode 100755 scripts/shutdown.sh create mode 100755 scripts/volume.sh create mode 100755 scripts/wallpaper.sh diff --git a/scripts/cpu-temp.sh b/scripts/cpu-temp.sh new file mode 100755 index 0000000..4ffbcd9 --- /dev/null +++ b/scripts/cpu-temp.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +sensors | awk '/^k10temp/ {getline; getline; print $2}' diff --git a/scripts/dmenumount.sh b/scripts/dmenumount.sh new file mode 100755 index 0000000..a282181 --- /dev/null +++ b/scripts/dmenumount.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +font="System San Francisco Display 12" + +pgrep -x dmenu && exit + +mountable=$(lsblk -lp | grep "part $" | awk '{print $1, "(" $4 ")"}') +[[ "${mountable}" = "" ]] && exit 1 +chosen=$(echo "${mountable}" | dmenu -fn "${font}" -i -p "Mount which drive?" | awk '{print $1}') +[[ "${chosen}" = "" ]] && exit 1 +mount "${chosen}" > /dev/null 2>&1 && notify-send "${chosen} mounted based on fstab" && exit 0 +dirs=$(find /mnt /media /home -type d -maxdepth 3 2>/dev/null) +mountpoint=$(echo "${dirs}" | dmenu -fn "${font}" -i -p "Type in mount point.") +[[ "${mountpoint}" = "" ]] && exit 1 +if [[ ! -d "${mountpoint}" ]]; then + mkdiryn=$(echo -e "Yes\nNo" | dmenu -fn "${font}" -i -p "${mountpoint} does not exist. Create it?") + [[ "${mkdiryn}" = Yes ]] && sudo mkdir -p "${mountpoint}" +fi +sudo mount $chosen $mountpoint -o uid="$(id -u `whoami`)",gid="$(id -g `whoami`)" && \ +notify-send "${chosen} mounted to ${mountpoint}" diff --git a/scripts/idea-reset.sh b/scripts/idea-reset.sh new file mode 100755 index 0000000..292e14d --- /dev/null +++ b/scripts/idea-reset.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +idea_config_loc=~/.IntelliJIdea2018.3/config +jetbrain_prefs=~/.java/.userPrefs/jetbrains/idea/30a67a02 + +echo "Clearing idea eval configs:" +echo "Idea local config: ${idea_config_loc}" +echo "Jetbrains java config: ${jetbrain_prefs}" + +rm -rf $idea_config_loc/eval && \ +sed -i '/.*evl.*/d' $idea_config_loc/options/other.xml && \ +rm -rf $jetbrain_prefs/evl* + +echo "Idea eval configs wiped out!" diff --git a/scripts/iface.sh b/scripts/iface.sh new file mode 100755 index 0000000..231e541 --- /dev/null +++ b/scripts/iface.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +icon= +iface=$(ip route | awk '/^default/ { print $5 ; exit }') + +[[ ! -d /sys/class/net/${iface} ]] && exit + +if [[ "$(cat /sys/class/net/$iface/operstate)" = 'down' ]]; then + printf '%s' "${icon} down" + exit +fi + +case $1 in + -4) + af=inet ;; + -6) + af=inet6 ;; + *) + af=inet6? ;; +esac + +ipaddr=$(ip addr show enp3s0 | awk '/inet/ { print $2 ; exit }' | sed 's/\/.*//g') +#echo $ipaddr +printf '%s' "${icon} ${ipaddr}" diff --git a/scripts/key-map.sh b/scripts/key-map.sh new file mode 100755 index 0000000..391ac29 --- /dev/null +++ b/scripts/key-map.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +setxkbmap -layout us,ru -option grp:ctrls_toggle diff --git a/scripts/keymap-switch.sh b/scripts/keymap-switch.sh new file mode 100755 index 0000000..6fefaed --- /dev/null +++ b/scripts/keymap-switch.sh @@ -0,0 +1,4 @@ + #!/bin/bash + +xkb-switch +xkb-switch -W diff --git a/scripts/mem.sh b/scripts/mem.sh new file mode 100755 index 0000000..50d4bc9 --- /dev/null +++ b/scripts/mem.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +mem_info() { + ps_out="$(ps axch -o cmd:15,pid,%mem --sort -%mem | head)" + + IFS=$(echo -en "\n\b") + fmt_msg="" + num=1 + for row in ${ps_out[@]}; do + name="$(echo -e $row | awk '{NF-=2; print $OFS}')" + pid="$(echo -e $row | awk '{NF-=1; print $NF}')" + mem="$(echo -e $row | awk '{print $NF}')" + fmt_msg=${fmt_msg}$(printf "%s\t%s|%s|%s" "$num" "$name" "$pid" "$mem%")"\n" + num=$(( $num + 1 )) + done + + fmt_msg=$(echo -e "${fmt_msg}" | column -s "|" -t -o " > ") + echo "${fmt_msg}" +} + +case $BLOCK_BUTTON in + 1) notify-send "Top 10 memory consumption" "$(mem_info)" -t 30000;; +esac + +free -h | awk '/^Mem:/ {print $3 "/" $2}' | sed 's/i//g' diff --git a/scripts/screen-locker.sh b/scripts/screen-locker.sh new file mode 100755 index 0000000..b5322fc --- /dev/null +++ b/scripts/screen-locker.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +icons_dir=Pictures/Icons +icon_file="$(ls $icons_dir | sort -R | head -n 1)" +icon=$HOME/$icons_dir/$icon_file +tmp_bg=/tmp/screen.png + +#echo $icon + +scrot $tmp_bg +convert $tmp_bg -scale 10% -scale 1000% $tmp_bg +convert $tmp_bg $icon -gravity center -composite -matte $tmp_bg +i3lock -u -i $tmp_bg diff --git a/scripts/shutdown.sh b/scripts/shutdown.sh new file mode 100755 index 0000000..75c5673 --- /dev/null +++ b/scripts/shutdown.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +font="System San Francisco Display 12" + +pgrep -x dmenu && exit + +chosen=$(echo -e "Shutdown\nReboot" | dmenu -fn "${font}" -i -p "What would you like to do?") +if [[ "${chosen}" = Shutdown ]]; then + yesno=$(echo -e "Yes\nNo" | dmenu -fn "${font}" -i -p "Do you really want to shutdown?") + [[ "${yesno}" = Yes ]] && sudo shutdown -h now +elif [[ "${chosen}" = Reboot ]]; then + yesno=$(echo -e "Yes\nNo" | dmenu -fn "${font}" -i -p "Do you really want to reboot?") + [[ "${yesno}" = Yes ]] && sudo reboot +fi diff --git a/scripts/volume.sh b/scripts/volume.sh new file mode 100755 index 0000000..e762517 --- /dev/null +++ b/scripts/volume.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +sink=$( pactl list short sinks | sed -e 's,^\([0-9][0-9]*\)[^0-9].*,\1,' | tail -n 1 ) + +case $BLOCK_BUTTON in + 2) pactl set-sink-mute $sink toggle ;; + 4) pactl set-sink-volume $sink +5% ;; + 5) pactl set-sink-volume $sink -5% ;; +esac + +muted=$( awk '/muted/ {print $2}' <(pacmd list-sinks | grep '^[[:space:]]muted:' | head -n $(( $sink + 1 )) | tail -n 1 ) ) + +if [ "$muted" = "yes" ]; then + icon="" + printf "%s\\n" "$icon" +else + vol=$( pactl list sinks | grep '^[[:space:]]Volume:' | head -n $(( $sink + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,' ) + if [ "$vol" -gt 60 ]; then + icon="" + elif [[ "$vol" -le 60 && "$vol" -gt 30 ]]; then + icon="" + else + icon="" + fi + + printf "%s %s%%\\n" "$icon" "$vol" +fi diff --git a/scripts/wallpaper.sh b/scripts/wallpaper.sh new file mode 100755 index 0000000..2ffc7f6 --- /dev/null +++ b/scripts/wallpaper.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +period=$1 +wp_dir=~/Pictures/wallpapers + +while true +do + cur_wp_name=$(ls -1 $wp_dir | shuf | head -n 1) + +# echo $cur_wp_name + feh --bg-scale $wp_dir/$cur_wp_name + + sleep ${period}m +done diff --git a/shell/.bash_profile.symlink b/shell/.bash_profile.symlink index 5e1ef83..dfac0ac 100644 --- a/shell/.bash_profile.symlink +++ b/shell/.bash_profile.symlink @@ -16,6 +16,7 @@ export DOT_FILES_VIM="${DOT_FILES}/vim" export DOT_FILES_VIM_C_DEV="${DOT_FILES_VIM}/c-dev" export DOT_FILES_SHELL="${DOT_FILES}/shell" export DOT_FILES_SHELL_INIT="${DOT_FILES_SHELL}/init_scripts" +export SCRIPTS="${HOME}/scripts" if [[ -d ${DOT_FILES_SHELL_INIT} ]]; then for s in $(ls -a ${DOT_FILES_SHELL_INIT} | grep -v "\.$"); do -- 2.39.5