summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJake VanderVaate <jake.vandervaate@protonmail.com>2022-02-28 22:12:51 -0600
committerJake VanderVaate <jake.vandervaate@protonmail.com>2022-02-28 22:12:51 -0600
commit33cf649f2d0f7a57c7a66250fa12aa5e9ce759b5 (patch)
tree94259b4b27a7efd37b0def338e365da32a0ee23e
parenta93db148848b034954be9b8be8dc69ad33615458 (diff)
initial commit, added status bar scripts
-rw-r--r--README.adoc82
-rw-r--r--README.md92
-rwxr-xr-xbattery-notify36
-rwxr-xr-xsb-battery26
-rwxr-xr-xsb-hdspace7
-rwxr-xr-xsb-ram7
-rwxr-xr-xsb-time9
-rwxr-xr-xsb-volume18
-rwxr-xr-xsb-wifi15
9 files changed, 200 insertions, 92 deletions
diff --git a/README.adoc b/README.adoc
new file mode 100644
index 0000000..f44e197
--- /dev/null
+++ b/README.adoc
@@ -0,0 +1,82 @@
+= My shell scripts
+
+These are the shell scripts I've written for a broad range of tasks.
+Move these into your $PATH to call them without needing to provide a full path to the script to run it.
+
+
+== General
+
+battery-notify::
+This script monitors battery levels for 2 battery systems and sends notifications via `notify-send` when the battery gets too low.
+At 5% the script notifies the user that the computer will lock in 60 seconds if not plugged in.
+If the computer isn't plugged in within 60 seconds, the screen locks with the command defined in the `lock_command` variable on line 3.
+
+== Status bar scripts (sb-*)
+
+These status bar scripts use the https://fontawesome.com/v5/search?m=free[free FontAwesome Icons].
+These scripts work for status bar programs like DWMBlocks, Polybar, or can be called in an `xsetroot` command.
+
+sb-battery::
+Displays a single, averaged battery percentage for laptops with two batteries.
+
+sb-hdspace::
+Displays the space available on a single hard drive.
+Users may have to adjust the row and column that the script reads from, depending on their system configuration.
+
+sb-ram::
+Displays the amount of random access memory (RAM) the system is currently using.
+
+sb-time::
+Displays the current date in IS0-8601 (YYYY-MM-DD) format, and the current time in 24-hour (HH:MM) format.
+
+sb-volume::
+Displays the current volume from the system's default PulseAudio sink.
+
+sb-wifi::
+Displays the the system's current wifi connection status.
+Do note that this just displays the system's connection with the wifi access point, and not the access point's connection to the internet (this script can show an active wifi status while not connected to the internet).
+
+=== Using these scripts in a status bar
+
+*DWMBlocks* blocks.h config
+
+[source,c]
+----
+static const Block blocks[] = {
+ /*Icon*/ /*Command*/ /*Update Interval*/ /*Update Signal*/
+ {"", "sb-wifi", 2, 0},
+ {"", "sb-volume", 2, 0},
+ {"", "sb-ram", 2, 0},
+ {"", "sb-hdspace", 360, 0},
+ {"", "sb-time", 15, 0},
+ {"", "sb-battery", 1, 0},
+};
+
+//sets delimeter between status commands. NULL character ('\0') means no delimeter.
+static char delim[] = " ";
+static unsigned int delimLen = 5;
+----
+
+*Polybar* config for calling a single module, on the right side of the status bar.
+Find these areas in the config file and change them as needed.
+
+[source,shell]
+----
+font-0 = Source Code Pro:pixelsize=10;1
+font-1 = Font Awesome 5 Free:size=10;1
+font-2 = Font Awesome 5 Free Solid:size=10;1
+font-3 = Font Awesome 5 Free Brands:size=10;1
+font-4 = siji:pixelsize=10;1
+
+modules-right = sb-ram
+
+[module/sb-ram]
+type = custom/script
+format-foreground = ${colors.foreground}
+format-prefix = ""
+format-padding = 1
+label = "%output%"
+initial = 1
+interval = 3
+exec = change/this/to/the/path/to/this/script
+----
diff --git a/README.md b/README.md
deleted file mode 100644
index 6204c2f..0000000
--- a/README.md
+++ /dev/null
@@ -1,92 +0,0 @@
-# sh
-
-These are the shell scripts I've written for a broad range of tasks
-
-## Getting started
-
-To make it easy for you to get started with GitLab, here's a list of recommended next steps.
-
-Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
-
-## Add your files
-
-- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
-- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
-
-```
-cd existing_repo
-git remote add origin https://gitlab.com/jakevandervaate/sh.git
-git branch -M main
-git push -uf origin main
-```
-
-## Integrate with your tools
-
-- [ ] [Set up project integrations](https://gitlab.com/jakevandervaate/sh/-/settings/integrations)
-
-## Collaborate with your team
-
-- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
-- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
-- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
-- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
-- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
-
-## Test and Deploy
-
-Use the built-in continuous integration in GitLab.
-
-- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
-- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
-- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
-- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
-- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
-
-***
-
-# Editing this README
-
-When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
-
-## Suggestions for a good README
-Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
-
-## Name
-Choose a self-explaining name for your project.
-
-## Description
-Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
-
-## Badges
-On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
-
-## Visuals
-Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
-
-## Installation
-Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
-
-## Usage
-Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
-
-## Support
-Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
-
-## Roadmap
-If you have ideas for releases in the future, it is a good idea to list them in the README.
-
-## Contributing
-State if you are open to contributions and what your requirements are for accepting them.
-
-For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
-
-You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
-
-## Authors and acknowledgment
-Show your appreciation to those who have contributed to the project.
-
-## License
-For open source projects, say how it is licensed.
-
-## Project status
-If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
diff --git a/battery-notify b/battery-notify
new file mode 100755
index 0000000..50099d7
--- /dev/null
+++ b/battery-notify
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+lock_command="slock"
+
+while true; do
+
+bat_0="$(cat /sys/class/power_supply/BAT0/capacity)"
+bat_1="$(cat /sys/class/power_supply/BAT1/capacity)"
+bats_total=$((bat_0+bat_1))
+bats_average=$((bats_total/2))
+
+if [ "$bats_average" = "99" ]
+then
+ :
+elif [ "$bats_average" = "25" ]
+then
+ notify-send "Battery" "Battery charge is $bats_average\%"
+elif [ "$bats_average" = "15" ]
+then
+ notify-send -u critical "Battery-Notify" "Battery charge is $bats_average\%\nPlug in immediately"
+elif [ "$bats_average" = "5" ]
+then
+ notify-send "Battery-Notify" "Laptop will hibernate in 1 minute"
+ sleep 60
+ if [ "$(cat /sys/class/power_supply/BAT0/status)" = "Not charging" ]
+ then
+ "$lock_command"
+ else
+ :
+ fi
+else
+ :
+fi
+
+sleep 180
+done
diff --git a/sb-battery b/sb-battery
new file mode 100755
index 0000000..65bb30d
--- /dev/null
+++ b/sb-battery
@@ -0,0 +1,26 @@
+#!/bin/sh
+#DWM Status Bar
+
+bat_0=$(cat /sys/class/power_supply/BAT0/capacity)
+bat_1=$(cat /sys/class/power_supply/BAT1/capacity)
+bats_total=$((bat_0+bat_1))
+bats_average=$((bats_total/2))
+
+if [ "$bats_average" -ge "85" ]
+then
+ echo "$bats_average%"
+elif [ "$bats_average" -ge "60" ] && [ "$bats_average" -le "84" ]
+then
+ echo "$bats_average%"
+elif [ "$bats_average" -ge "40" ] && [ "$bats_average" -le "59" ]
+then
+ echo "$bats_average%"
+elif [ "$bats_average" -ge "15" ] && [ "$bats_average" -le "39" ]
+then
+ echo "$bats_average%"
+elif [ "$bats_average" -le "15" ]
+then
+ echo "$bats_average%"
+else
+ :
+fi
diff --git a/sb-hdspace b/sb-hdspace
new file mode 100755
index 0000000..2a90d34
--- /dev/null
+++ b/sb-hdspace
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+# row from df-h input v
+hd_space="$(df -h | awk '(NR==4){print $4}')"
+# column from df -h output ^
+
+echo "$hd_space"
diff --git a/sb-ram b/sb-ram
new file mode 100755
index 0000000..7033cbb
--- /dev/null
+++ b/sb-ram
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+# colum of free -h v
+ram_used="$(free -h | awk '(NR==2){print $3}')"
+# row from free -h ^
+
+echo "$ram_used"
diff --git a/sb-time b/sb-time
new file mode 100755
index 0000000..a582aa6
--- /dev/null
+++ b/sb-time
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+#Date is in ISO-8601 YYYY-MM-DD format
+date="$(date +%Y-%m-%d)"
+
+#Time is in 24H HH:MM format
+time="$(date +%H:%M)"
+
+echo "$date $time"
diff --git a/sb-volume b/sb-volume
new file mode 100755
index 0000000..1114d49
--- /dev/null
+++ b/sb-volume
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+volume="$(pactl list sinks | grep '^[[:space:]]Volume:' | \head -n $((SINK+1)) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,')"
+mute="$(pactl get-sink-mute 0 | sed 's/^Mute:\ //g')"
+
+if [ "$mute" = 'yes' ]
+then
+ echo ""
+
+elif [ "$mute" = 'no' ]
+then
+ echo "$volume"
+
+else
+ echo ""
+fi
+
+
diff --git a/sb-wifi b/sb-wifi
new file mode 100755
index 0000000..5498436
--- /dev/null
+++ b/sb-wifi
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+wifi_interface="wlp4s0"
+
+wifi_status="$(nmcli | grep "^$wifi_interface" | awk '(NR==1){print $2}')"
+
+if [ "$wifi_status" = "connected" ]
+then
+ echo ""
+elif [ "$wifi_status" = "unavailable" ]
+then
+ echo ""
+else
+ echo ""
+fi