Compare commits
6 Commits
f2cac45139
...
master
Author | SHA1 | Date | |
---|---|---|---|
45a99b283d | |||
406aeb2d8f | |||
b62098c5b1 | |||
383eb1a728 | |||
93844008f3 | |||
bb20acab34 |
62
add-appimage-to-apps
Executable file
62
add-appimage-to-apps
Executable file
@@ -0,0 +1,62 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Check if an AppImage path is provided
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: $0 /path/to/AppImage"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Absolute path to the AppImage
|
||||
APPIMAGE_PATH="$(realpath "$1")"
|
||||
# Application destination dir
|
||||
APPDIR="$HOME/.local/share/applications"
|
||||
# A place to store application icons
|
||||
ICONDIR="$HOME/.local/share/icons"
|
||||
|
||||
# Make a tempdir and cd into it
|
||||
EXTRACT_DIR=$(mktemp -d)
|
||||
cleanup() {
|
||||
[ -z "$EXTRACT_DIR" ] && exit 2
|
||||
rm -rf "$EXTRACT_DIR"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
pushd "$EXTRACT_DIR"
|
||||
|
||||
# Extract AppImage
|
||||
"$APPIMAGE_PATH" --appimage-extract > /dev/null 2>&1
|
||||
# Find the extracted desktop file and icon
|
||||
DESKTOP_FILE=$(find "$EXTRACT_DIR/squashfs-root" -name "*.desktop" | head -n 1)
|
||||
# GPT spat this out and I'm really not sure if it's correct. I don't think
|
||||
# fd spec limits us to these two file formats
|
||||
ICON_FILE=$(find "$EXTRACT_DIR/squashfs-root" -name "*.png" -o -name "*.svg" | head -n 1)
|
||||
|
||||
if [ -z "$DESKTOP_FILE" ]; then
|
||||
echo "Error: No .desktop file found in AppImage."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Jump out of the tempdir. We now have absolute paths to the things we want
|
||||
popd
|
||||
|
||||
APP_NAME=$(grep -m1 '^Name=' "$DESKTOP_FILE" | cut -d= -f2)
|
||||
DESKTOP_TARGET="$APPDIR/$APP_NAME.desktop"
|
||||
ICON_TARGET="$ICONDIR/$APP_NAME.${ICON_FILE##*.}"
|
||||
# Copy the icon over
|
||||
mkdir -p "$ICONDIR"
|
||||
cp "$ICON_FILE" "$ICON_TARGET"
|
||||
# Update paths in the .desktop file and copy it over
|
||||
sed -e "s|^Exec=.*|Exec=$APPIMAGE_PATH|" \
|
||||
-e "s|^Icon=.*|Icon=$ICON_TARGET|" \
|
||||
"$DESKTOP_FILE" > "$DESKTOP_TARGET"
|
||||
# Ensure the desktop file is executable
|
||||
chmod +x "$DESKTOP_TARGET"
|
||||
|
||||
# Refresh application menu
|
||||
update-desktop-database "$APPDIR"
|
||||
|
||||
echo "Desktop entry created: $DESKTOP_TARGET"
|
||||
echo "Icon saved at: $ICON_TARGET"
|
||||
echo "You can now launch '$APP_NAME' from your application menu."
|
||||
|
10
packetloss
10
packetloss
@@ -1,11 +1,11 @@
|
||||
#! /bin/bash
|
||||
|
||||
declare -i samples=100
|
||||
declare -a servers=('1.1.1.1' '8.8.8.8')
|
||||
declare -a servers=('8.8.8.8')
|
||||
declare -i highestloss=0
|
||||
|
||||
declare -i alltimehighest=0
|
||||
declare -i alltimelowest=0
|
||||
declare -i alltimelowest=100
|
||||
declare -i iterations=1
|
||||
|
||||
while :; do
|
||||
@@ -23,6 +23,12 @@ while :; do
|
||||
if (( highestloss > 0 )); then
|
||||
color="\e[31m"
|
||||
fi
|
||||
if (( highestloss > alltimehighest )); then
|
||||
alltimehighest="$highestloss"
|
||||
fi
|
||||
if (( highestloss < alltimelowest )); then
|
||||
alltimelowest="$highestloss"
|
||||
fi
|
||||
printf "\\rCurrent loss: $color%-3.3s\e[0m - \e[33m%-4.4s \e[34m%-4.4s \e[0m%-4.4s" \
|
||||
"$highestloss" \
|
||||
"$alltimehighest" \
|
||||
|
10
switchsession
Executable file
10
switchsession
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
which busctl > /dev/null 2>&1
|
||||
# Get the current Seat
|
||||
SEAT=$(busctl get-property org.freedesktop.login1 /org/freedesktop/login1/session/auto org.freedesktop.login1.Session Seat | awk '{print $2}' | tr -d '"' | sed 's/^./\U&/')
|
||||
# Call out to switch the current session
|
||||
busctl call org.freedesktop.DisplayManager "/org/freedesktop/DisplayManager/${SEAT}" org.freedesktop.DisplayManager.Seat SwitchToGreeter
|
||||
# Lock
|
||||
loginctl lock-session
|
165
tick
Executable file
165
tick
Executable file
@@ -0,0 +1,165 @@
|
||||
#! /bin/bash
|
||||
#
|
||||
# tick
|
||||
# A program to get the price of a symbol from Binance
|
||||
# Copyright (C) 2021 Vintage Salt <rehashedsalt@cock.li>
|
||||
#
|
||||
# Distributed under terms of the MIT license.
|
||||
#
|
||||
set -e
|
||||
|
||||
# Read-only set-once variables
|
||||
declare -r _name="$(basename -- "$0")"
|
||||
# Options
|
||||
declare -i _opthelp
|
||||
declare -i _optverbose
|
||||
declare -i _optcolor
|
||||
declare _optsymbol
|
||||
# Working variables
|
||||
declare -a _args
|
||||
declare _return
|
||||
|
||||
# Helper functions
|
||||
log() {
|
||||
# Print a line to the terminal if _optverbose is greater than $2
|
||||
# $2 defaults to 0
|
||||
# loglevel 0: Daily-use messages
|
||||
# loglevel 1: Detailed but not quite debugging
|
||||
# loglevel 2: Definitely debugging
|
||||
[ -z "$1" ] && return 1
|
||||
if (( _optverbose >= ${2:-0} )); then
|
||||
printf "%s\\n" "$1"
|
||||
fi
|
||||
}
|
||||
warn() {
|
||||
# Print a yellow line to the terminal, respecting _optverbose
|
||||
[ -z "$1" ] && return 1
|
||||
if (( _optverbose >= ${2:-0} )); then
|
||||
if [ -t 1 ]; then
|
||||
printf "\\e[33m%s\\e[0m\\n" "$1"
|
||||
else
|
||||
printf "WARN: %s\\n" "$1"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
error() {
|
||||
# Print a red line to the terminal, exit if $2 is specified
|
||||
[ -z "$1" ] && return 1
|
||||
if [ -t 2 ]; then
|
||||
printf "\\e[31m%s\\e[0m\\n" "$1" 1>&2
|
||||
else
|
||||
printf "ERROR: %s\\n" "$1" 1>&2
|
||||
fi
|
||||
[ -z "$2" ] && return
|
||||
exit "${2:-1}"
|
||||
}
|
||||
has() {
|
||||
# Parse out all arguments and try to find them in path
|
||||
# If an argument cannot be found, set _return and fail
|
||||
for prog in "$@"; do
|
||||
if ! command -v "$prog" > /dev/null 2>&1; then
|
||||
_return="$prog"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
# Core program functions
|
||||
printhelp() {
|
||||
cat << EOF
|
||||
Usage: $_name [OPTION]... SYMBOL
|
||||
Get the 24hr price change for a particular symbol from Binance
|
||||
|
||||
-c Add color to the output
|
||||
-d SYMBOL Change the symbol displayed. Useful for comparisons against USDC
|
||||
and other stablecoins
|
||||
-h Print this help text
|
||||
-v Print more status messages. Stacks
|
||||
|
||||
Copyright (c) 2021 rehashedsalt@cock.li
|
||||
Licensed under the MIT license
|
||||
EOF
|
||||
}
|
||||
getprice() {
|
||||
# Get the price of a coin from Binance
|
||||
[ -z "$1" ] && return 1
|
||||
symbol="$1"
|
||||
result="$(curl -sL "https://api.binance.com/api/v3/ticker/24hr?symbol=$symbol")"
|
||||
# Test to see if we got an error
|
||||
if echo "$result" | jq '.code' -e > /dev/null 2>&1; then
|
||||
code="$(echo "$result" | jq -re '.code')"
|
||||
msg="$(echo "$result" | jq -re '.msg')"
|
||||
error "Error $code: $msg" 51
|
||||
fi
|
||||
# Parse out the data
|
||||
if [ -n "$_optsymbol" ]; then
|
||||
symbol="$_optsymbol"
|
||||
else
|
||||
symbol="$(echo "$result" | jq -re '.symbol')"
|
||||
fi
|
||||
price="$(echo "$result" | jq -re '.priceChangePercent')"
|
||||
if [ -n "$_optcolor" ]; then
|
||||
if [[ "$price" == -* ]]; then
|
||||
price="\e[31m$price\e[0m"
|
||||
else
|
||||
price="\e[32m$price\e[0m"
|
||||
fi
|
||||
fi
|
||||
printf "$symbol $price\n"
|
||||
}
|
||||
|
||||
# Main
|
||||
main() {
|
||||
# Parse out arguments
|
||||
while [ -n "$1" ]; do
|
||||
# Parse out flags
|
||||
while getopts ":cd:hv" opt; do
|
||||
case $opt in
|
||||
c)
|
||||
_optcolor=1
|
||||
;;
|
||||
d)
|
||||
_optsymbol="$OPTARG"
|
||||
;;
|
||||
h)
|
||||
_opthelp=1
|
||||
;;
|
||||
v)
|
||||
_optverbose+=1
|
||||
;;
|
||||
:)
|
||||
error "Option requires argument: -$OPTARG" 2
|
||||
;;
|
||||
*)
|
||||
error "Invalid option: -$OPTARG" 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
# Store arguments
|
||||
shift $((OPTIND - 1))
|
||||
if [ -n "$1" ]; then
|
||||
_args+=("$1")
|
||||
shift
|
||||
fi
|
||||
unset OPTIND
|
||||
done
|
||||
# Early hook for help
|
||||
[ -n "$_opthelp" ] && printhelp && exit 0
|
||||
# Validate critical options
|
||||
if [ -z "${_args[*]}" ]; then
|
||||
error "No symbol specified" 50
|
||||
fi
|
||||
# Validate core program dependencies
|
||||
log "Validating dependencies" 2
|
||||
if ! has basename curl jq; then
|
||||
error "Failed to find program: $_return" 1
|
||||
fi
|
||||
|
||||
# Do the do
|
||||
getprice "${_args[0]}"
|
||||
exit 0
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
Reference in New Issue
Block a user