From 8dd49608b800c706914de326dc1a4cafefa6fa7d Mon Sep 17 00:00:00 2001 From: Adam Veldhousen Date: Sat, 16 Oct 2021 17:23:38 -0500 Subject: [PATCH] chore: add waybar and CI --- .config/waybar/config | 74 +++++++++++++++++ .config/waybar/start.sh | 8 ++ .config/waybar/style.css | 121 +++++++++++++++++++++++++++ .github/workflows/build-image.yml | 16 ++++ Dockerfile | 2 +- makefile | 8 ++ plugins/899-helpers.sh | 132 ++++++++++++++++++++++++++++++ plugins/900-prompt.sh | 9 ++ 8 files changed, 369 insertions(+), 1 deletion(-) create mode 100644 .config/waybar/config create mode 100755 .config/waybar/start.sh create mode 100644 .config/waybar/style.css create mode 100644 .github/workflows/build-image.yml create mode 100644 plugins/899-helpers.sh diff --git a/.config/waybar/config b/.config/waybar/config new file mode 100644 index 0000000..92e60f1 --- /dev/null +++ b/.config/waybar/config @@ -0,0 +1,74 @@ +{ + "layer": "top", + "height": 20, + "modules-left": [ + "sway/workspaces", + "sway/mode", + "sway/window" + ], + "modules-center": [], + "modules-right": [ + "idle_inhibitor", + "backlight", + "memory", + "network", + "custom/powerbar", + "clock", + "tray" + ], + "sway/window": { + "max-length": 100, + "rewrite": { + "(.*) - Mozilla Firefox$": "🌎 $1", + "(.*) - vim": " $1", + "(.*) - zsh": " [$1]", + "(.*) - /bin/bash": " [$1]" + } + }, + "memory": { + "format": "RAM: {}%" + }, + "network": { + "format-wifi": " ({signalStrength}%) {essid}", + "format-ethernet": "{ifname}: {ipaddr}/{cidr} ", + "format-linked": "{ifname} (No IP) ", + "format-disconnected": "Disconnected ⚠", + "format-alt": "{ifname}: {ipaddr}/{cidr}" + }, + "custom/powerbar": { + "return-type": "json", + "interval": 3, + "exec": "/bin/powerbar -full 'FULL - {usage}W' -charging '{state} {capacity}% - {usage}W - {H}h {M}m' -waybar 2> /dev/null" + }, + "battery": { + "format": "{icon} {capacity}%", + "format-icons": [ + "", + "", + "", + "", + "" + ] + }, + "clock": { + "format": "{:%a, %d. %b %H:%M}" + }, + "idle_inhibitor": { + "format": "{icon}", + "format-icons": { + "activated": "No Sleep ", + "deactivated": "" + } + }, + "backlight": { + "device": "intel_backlight", + "format": "{icon} 100%", + "format-icons": [ + "", + "" + ] + }, + "tray": { + "spacing": 10 + } +} diff --git a/.config/waybar/start.sh b/.config/waybar/start.sh new file mode 100755 index 0000000..0ed09cf --- /dev/null +++ b/.config/waybar/start.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +killall -q waybar +while pgrep -x waybar > /dev/null; do sleep 0.1; done +if [[ -s "$(which waybar)" ]]; then + dunstify -a "waybar" "Starting up waybar" + exec waybar -c ~/.config/waybar/config +fi diff --git a/.config/waybar/style.css b/.config/waybar/style.css new file mode 100644 index 0000000..c229081 --- /dev/null +++ b/.config/waybar/style.css @@ -0,0 +1,121 @@ +/* + * https://coolors.co/264653-2a9d8f-e9c46a-f4a261-e76f51 + * $charcoal: rgba(38, 70, 83, 1); + * $persian-green: rgba(42, 157, 143, 1); + * $orange-yellow-crayola: rgba(233, 196, 106, 1); + * $sandy-brown: rgba(244, 162, 97, 1); + * $burnt-sienna: rgba(231, 111, 81, 1); + */ + +* { + border: none; + border-radius: 0; + font-family: "Pragmata Pro", Roboto, Helvetica, Arial, sans-serif; + font-size: 18px; + min-height: 0; +} + +window#waybar { + background: rgba(43, 48, 59, 0.5); + border-bottom: 3px solid rgba(100, 114, 125, 0.5); + color: white; +} + +tooltip { + background: rgba(43, 48, 59, 0.5); + border: 1px solid rgba(100, 114, 125, 0.5); +} + +tooltip label { + color: white; +} + +#workspaces button { + padding: 0 5px; + background: transparent; + color: white; + border-bottom: 3px solid transparent; +} + +#workspaces button.focused { + background: #64727D; + border-bottom: 3px solid white; +} + + +@keyframes blink { + to { + background-color: #ffffff; + color: black; + } +} + +#mode, +#clock, +#battery, +#tray, +#network, +#memory, +#backlight, +#idle-inhibitor, +#custom-powerbar { + padding: 0 10px; + margin: 0 5px; + border-bottom: 1px solid rgba(38, 70, 83, 1); +} + +#mode { + background: #64727D; + border-bottom: 3px solid white; +} + +#clock { + background-color: #64727D; +} + +#battery { + background-color: #ffffff; + color: black; +} + +#battery.charging { + color: white; + background-color: #26A65B; +} + + +#custom-powerbar { + border-bottom: 0px solid rgba(0, 255, 0, 1); +} + +#custom-powerbar.warning:not(.charging) { + background: #f53c3c; + color: white; + animation-name: blink; + animation-duration: 0.5s; + animation-timing-function: linear; + animation-iteration-count: infinite; + animation-direction: alternate; +} + +#custom-powerbar.charging, +#custom-powerbar.fully-charged { + border-bottom: 2px solid rgb(0, 255, 0); +} + +#custom-powerbar.discharging { + border-bottom: 2px solid rgba(233, 196, 106, 1); +} + +#network.wifi { + border-bottom: 2px solid rgba(42, 157, 143, 1); +} + +#network.disconnected { + color: rgba(231, 111, 81, 1); + border-bottom: 2px solid rgba(231, 111, 81, 1); +} + +#window { + padding: 0 10px; +} diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml new file mode 100644 index 0000000..636d0c4 --- /dev/null +++ b/.github/workflows/build-image.yml @@ -0,0 +1,16 @@ +name: Docker Image CI + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Build the Docker image + env: + DOCKER_USER: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASS: ${{ secrets.DOCKER_PASSWORD }} + run: | + docker login -u ${DOCKER_USER} -p ${DOCKER_PASS} + VERSION=${GITHUB_REF#"refs/heads/"} COMMIT_SHA=${GITHUB_SHA} INITIATOR=${GITHUB_ACTOR} make publish diff --git a/Dockerfile b/Dockerfile index 210d2b2..9d64682 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN pacman -Sy --noconfirm openssh sudo vim git which gnupg make gcc binutils bi WORKDIR /home/files COPY --chown=1000:1000 . /home/files/.files USER 1000 -RUN rm -rf /home/files/.bashrc \ +RUN rm -rf .bash_rc .bash_logout .zshrc \ && source /home/files/.files/sourceme.sh \ && echo "source /home/files/.files/sourceme.sh" > /home/files/.bash_profile diff --git a/makefile b/makefile index 5f68229..f7706b4 100644 --- a/makefile +++ b/makefile @@ -6,3 +6,11 @@ dev: .PHONY: build build: @docker build -t adamveld12/files . + +SHA:=$(shell git rev-parse --short=6 HEAD) + +.PHONY: publish +publish: + docker build -t adamveld12/files:latest -t adamveld12/files:$(SHA) . + docker push adamveld12/files:$(SHA) + docker push adamveld12/files:latest diff --git a/plugins/899-helpers.sh b/plugins/899-helpers.sh new file mode 100644 index 0000000..a6fd145 --- /dev/null +++ b/plugins/899-helpers.sh @@ -0,0 +1,132 @@ +#!/bin/sh + +# kill the process using the specified port +function freeport(){ + + if [ -z $1 ]; then + echo "usage: freeport " >&2 + return 1 + fi + + lsof -t -i tcp:$1 | xargs kill +} + +# runs tcp dump on the port specified in $1. $1 defaults to 8080 +function dumptcp(){ + local DUMPPORT=$1 + local DUMPINTERFACE=$2 + + if [ -z "$1" ]; then + DUMPPORT=8080 + elif [[ "$1" == "help" ]]; then + echo "dumps tcp info at the specified port. Useful for looking at http requests" + echo "usage dumptcp " + return 1 + fi + + if [ -z "$2" ]; then + DUMPINTERFACE=lo0 + fi + + echo "dumping tcp connections @ $DUMPINTERFACE on port $DUMPPORT..." + + sudo tcpdump -s 0 -A -i $DUMPINTERFACE "tcp port $DUMPPORT and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)" +} + +# Determine size of a file or total size of a directory +function fs() { + if du -b /dev/null > /dev/null 2>&1; then + local arg=-sbh; + else + local arg=-sh; + fi + if [[ -n "$@" ]]; then + du $arg -- "$@"; + else + du $arg .[^.]* *; + fi; +} + +# Run `dig` and display the most useful info +function digga() { + dig +nocmd "$1" any +multiline +noall +answer; +} + + +# `o` with no arguments opens the current directory, otherwise opens the given +# location +function o() { + if [ $# -eq 0 ]; then + open .; + else + open "$@"; + fi; +} + +# Create a .tar.gz archive, using `zopfli`, `pigz` or `gzip` for compression +function targz() { + local tmpFile="${@%/}.tar"; + tar -cvf "${tmpFile}" --exclude=".DS_Store" "${@}" || return 1; + + size=$( + stat -f"%z" "${tmpFile}" 2> /dev/null; # OS X `stat` + stat -c"%s" "${tmpFile}" 2> /dev/null # GNU `stat` + ); + + local cmd=""; + if (( size < 52428800 )) && hash zopfli 2> /dev/null; then + # the .tar file is smaller than 50 MB and Zopfli is available; use it + cmd="zopfli"; + else + if hash pigz 2> /dev/null; then + cmd="pigz"; + else + cmd="gzip"; + fi; + fi; + + echo "Compressing .tar using \`${cmd}\`…"; + "${cmd}" -v "${tmpFile}" || return 1; + [ -f "${tmpFile}" ] && rm "${tmpFile}"; + echo "${tmpFile}.gz created successfully."; +} + + +# Syntax-highlight JSON strings or files +# Usage: `json '{"foo":42}'` or `echo '{"foo":42}' | json` +function json() { + if [ -t 0 ]; then # argument + python -mjson.tool <<< "$*" | pygmentize -l javascript; + else # pipe + python -mjson.tool | pygmentize -l javascript; + fi; +} + +function interfaces(){ + ifconfig | grep "\: flags" | awk '{print $1}' | sed 's/:$//'; +} + +function inline_image { + printf '\033]1338;url='"$1"';alt='"$2"'\a\n' +} + +# Create a git.io short URL +function gitio() { + if [ -z "${1}" -o -z "${2}" ]; then + echo "Usage: \`gitio slug url\`"; + return 1; + fi; + curl -i http://git.io/ -F "url=${2}" -F "code=${1}"; +} + +# list files +alias ll='ls -hGla --color' + +#git +alias gs='git status' +alias gm='git merge --ff-only' +alias gpr='git pull --rebase' +alias gmt='git mergetool' +alias grc='git rebase --continue' +alias gk='git fetch origin; git remote prune origin; gitk --all &' +alias gl='git log --pretty=format:"%h %ar by %an: %s"' diff --git a/plugins/900-prompt.sh b/plugins/900-prompt.sh index 96bc5c4..a6cf6a1 100644 --- a/plugins/900-prompt.sh +++ b/plugins/900-prompt.sh @@ -150,4 +150,13 @@ else export PROMPT_COMMAND='PS1="$(history -a; history -c; history -r; build_prompt_unix)\n\$LA "' fi +if ! [[ -f "${HOME}/.bash_logout" ]]; then +files_debug_log "setting up .bash_logout for privacy" +cat <<- EOF > ${HOME}/.bash_logout + # when leaving the console clear the screen to increase privacy + if [ "$SHLVL" = 1 ]; then + [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q + fi +EOF +fi