clean up setup directory

This commit is contained in:
FollieHiyuki 2021-02-18 18:17:03 +03:00
parent 2baf168585
commit fd3511d513
No known key found for this signature in database
GPG Key ID: 813CF484F4993419
15 changed files with 23 additions and 780 deletions

View File

@ -20,7 +20,7 @@
- Fonts: **[Sarasa Gothic](https://github.com/be5invis/Sarasa-Gothic)** + **Iosevka Nerd Font** - Fonts: **[Sarasa Gothic](https://github.com/be5invis/Sarasa-Gothic)** + **Iosevka Nerd Font**
- Other dependencies: - Other dependencies:
- jq, sysstat, psmisc, wireless_tools (status on spectrwm's bar) - jq, sysstat, psmisc, wireless_tools (status info on spectrwm's bar)
- [light](https://github.com/haikarainen/light) / [brightnessctl](https://github.com/Hummer12007/brightnessctl) - [light](https://github.com/haikarainen/light) / [brightnessctl](https://github.com/Hummer12007/brightnessctl)
- [bottom](https://github.com/clementtsang/bottom) - [bottom](https://github.com/clementtsang/bottom)
- [fzf](https://github.com/junegunn/fzf), [fd](https://github.com/sharkdp/fd), [ripgrep](https://github.com/BurntSushi/ripgrep) - [fzf](https://github.com/junegunn/fzf), [fd](https://github.com/sharkdp/fd), [ripgrep](https://github.com/BurntSushi/ripgrep)
@ -30,6 +30,7 @@
- [starship](https://starship.rs/) - [starship](https://starship.rs/)
- [gallery-dl](https://github.com/mikf/gallery-dl) / [mangadl-bash](https://github.com/Akianonymus/mangadl-bash) - [gallery-dl](https://github.com/mikf/gallery-dl) / [mangadl-bash](https://github.com/Akianonymus/mangadl-bash)
- [translate-shell](https://github.com/soimort/translate-shell) - [translate-shell](https://github.com/soimort/translate-shell)
- [ddgr](https://github.com/jarun/ddgr), [buku](https://github.com/jarun/buku)
- [pulsemixer](https://github.com/GeorgeFilipkin/pulsemixer) - [pulsemixer](https://github.com/GeorgeFilipkin/pulsemixer)
- [nwg-launchers](https://github.com/nwg-piotr/nwg-launchers) / [wofi](https://hg.sr.ht/~scoopta/wofi) - [nwg-launchers](https://github.com/nwg-piotr/nwg-launchers) / [wofi](https://hg.sr.ht/~scoopta/wofi)
- [rofi](https://github.com/davatorium/rofi) / [dmenu](https://git.disroot.org/FollieHiyuki/dmenu) - [rofi](https://github.com/davatorium/rofi) / [dmenu](https://git.disroot.org/FollieHiyuki/dmenu)
@ -65,7 +66,6 @@
- I use some scripts from other people: - I use some scripts from other people:
- [some fzf scripts](https://github.com/DanielFGray/fzf-scripts) - [some fzf scripts](https://github.com/DanielFGray/fzf-scripts)
- [colorscripts](https://gitlab.com/dwt1/shell-color-scripts) - [colorscripts](https://gitlab.com/dwt1/shell-color-scripts)
- **farge**, **tmpsms** and **tmpmail** from [@sdushantha](https://github.com/sdushantha)
- **ytmenu** from [here](https://github.com/sayan01/scripts) - **ytmenu** from [here](https://github.com/sayan01/scripts)
- You want some more **kawaii** wallpapers? Here is the list of artists: [@rimuu](https://rimuu.com/), [@hiten](https://www.pixiv.net/users/490219/artworks), [@Tiv](https://www.pixiv.net/en/users/35081), [@mery](https://www.pixiv.net/en/users/2750098), [@Mashima_saki](https://www.pixiv.net/en/users/18403608), [@Yuuki_Tatsuya](https://www.pixiv.net/en/users/27691), [@Bison倉鼠](https://www.pixiv.net/en/users/333556/artworks), [@Dana](https://twitter.com/hapong07), [@gomzi](https://twitter.com/gcmzi), [@Rella](https://twitter.com/Rellakinoko), [@dnwls3010](https://twitter.com/dnwls3010), [@Shigure_Ui](https://www.pixiv.net/en/users/431873), [@QuAn_](https://www.pixiv.net/en/users/6657532/artworks), [@杉87](https://twitter.com/k_su_keke1121), [@fuzichoco](https://twitter.com/fuzichoco), [@Astero](https://twitter.com/asteroid_ill), [@shin556](https://www.pixiv.net/en/users/642762) - You want some more **kawaii** wallpapers? Here is the list of artists: [@rimuu](https://rimuu.com/), [@hiten](https://www.pixiv.net/users/490219/artworks), [@Tiv](https://www.pixiv.net/en/users/35081), [@mery](https://www.pixiv.net/en/users/2750098), [@Mashima_saki](https://www.pixiv.net/en/users/18403608), [@Yuuki_Tatsuya](https://www.pixiv.net/en/users/27691), [@Bison倉鼠](https://www.pixiv.net/en/users/333556/artworks), [@Dana](https://twitter.com/hapong07), [@gomzi](https://twitter.com/gcmzi), [@Rella](https://twitter.com/Rellakinoko), [@dnwls3010](https://twitter.com/dnwls3010), [@Shigure_Ui](https://www.pixiv.net/en/users/431873), [@QuAn_](https://www.pixiv.net/en/users/6657532/artworks), [@杉87](https://twitter.com/k_su_keke1121), [@fuzichoco](https://twitter.com/fuzichoco), [@Astero](https://twitter.com/asteroid_ill), [@shin556](https://www.pixiv.net/en/users/642762)

View File

@ -54,6 +54,7 @@
(package! exwm-edit) (package! exwm-edit)
;;(package! system-packages) ;;(package! system-packages)
(package! desktop-environment) (package! desktop-environment)
(package! ebuku)
;;(package! emms) ;;(package! emms)
;;(package! emms-mode-line-cycle) ;;(package! emms-mode-line-cycle)

View File

@ -30,7 +30,8 @@ overlay_text = [$imv_current_index/$imv_file_count] $imv_current_file [${imv_wid
[binds] [binds]
# Define some key bindings # Define some key bindings
q = quit q = quit
y = exec echo working! <Ctrl+d> = exec rm -f $imv_current_file; next
<Delete> = exec rm -f $imv_current_file; next
# Image navigation # Image navigation
<Left> = prev <Left> = prev

View File

@ -38,8 +38,8 @@ c.content.geolocation = False
# Headers # Headers
c.content.headers.accept_language = 'en-US,en;q=0.5' c.content.headers.accept_language = 'en-US,en;q=0.5'
c.content.headers.custom = {"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"} c.content.headers.custom = {"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"}
# c.content.headers.do_not_track = True c.content.headers.do_not_track = True
# c.content.headers.referer = 'same-domain' c.content.headers.referer = 'same-domain'
# From current TorBrowser # From current TorBrowser
c.content.headers.user_agent = 'Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0' c.content.headers.user_agent = 'Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0'

View File

@ -1,222 +0,0 @@
#!/usr/bin/env bash
# ┌─┐┌─┐┬─┐┌─┐┌─┐
# ├┤ ├─┤├┬┘│ ┬├┤
# ┴ ┴ ┴┴└─└─┘└─┘
# Created by Siddharth Dushantha
#
# Dependencies:
# bash
# imagemagick
# feh (Other: mpv or sxiv, but you must specify it using the --image-viewer flag)
#
# If you use X11
# colorpicker (https://github.com/ym1234/colorpicker)
#
# If you use Wayland
# slurp (https://wayland.emersion.fr/slurp)
# grim (https://wayland.emersion.fr/grim)
# wl-copy (https://github.com/bugaevc/wl-clipboard)
VERSION="1.0.8"
TEMP_DIR=/tmp/farge
MSG=${XDG_CACHE_HOME:-$HOME/.cache}/farge.msg
COLOR_TYPE="hex"
WRITE_COLOR_CODE=true
PREVIEW=true
IMAGE_VIEWER="imv"
STDOUT=false
NOTIFICATION=false
EXPIRE_TIME=120000
show_help() {
cat <<EOF
usage: farge [OPTIONS...]
┌─┐┌─┐┬─┐┌─┐┌─┐
├┤ ├─┤├┬┘│ ┬├┤
┴ ┴ ┴┴└─└─┘└─┘
Click on a pixel on your screen and show its color value
optional arguments:
--help (-h) show this help message and exit
--version (-v) show the version of farge you are using
--no-preview dont show the selected color in a preview window
--no-color-code dont write the color code on the preview window
--rgb show the color code as RGB instead of HEX
--image-viewer image viewer to use to show the preview (feh, mpv, sxiv)
--notify send the color code as notification, where the icon is the selected color
--expire-time amount of time the notification should be visible, in milliseconds
--stdout output the color value to stdout
EOF
}
hex_to_rgb() {
# Convert a hex value WITHOUT the hashtag (#)
R=$(printf "%d" 0x"${1:0:2}")
G=$(printf "%d" 0x"${1:2:2}")
B=$(printf "%d" 0x"${1:4:2}")
}
check_dependencies() {
# Only check colorpicker if it's running in X,else check for slurp and grim
if [ "$WAYLAND_DISPLAY" ]; then
! command -v grim &>/dev/null &&
echo "grim need to be installed: https://wayland.emersion.fr/grim" && v=" "
! command -v slurp &>/dev/null &&
echo "slurp needs to be installed: https://wayland.emersion.fr/slurp" && v=" "
! command -v wl-copy &>/dev/null &&
echo "wl-copy needs to be installed: https://github.com/bugaevc/wl-clipboard" && v=" "
[ "$v" ] && exit 1
unset v
else
! command -v colorpicker &>/dev/null &&
echo "colorpicker need to be installed: https://github.com/ym1234/colorpicker" && exit 1
fi
! command -v convert &>/dev/null &&
echo "imagemagick needs to be installed" && exit 1
# We are using the variable $IMAGE_VIEWER because we also have to check if
# the image viewer the user has told us to use actually exists.
# If the user wants to show the color and the color code through a notification,
# then do not check if they have the image viewer installed because it wont be used
[ $NOTIFICATION == false ] &&
! command -v $IMAGE_VIEWER &>/dev/null &&
echo "$IMAGE_VIEWER needs to be installed or use another image by using --image-viewer <name>" &&
exit 1
}
# Caclulate math equations with decimals. This is better than $(())
calc(){ awk "BEGIN { print $*}"; }
calculate_text_color(){
# I dont even know why this equation works
# Source: https://stackoverflow.com/a/3943023
INTENSITY=$(calc "$R*0.299 + $G*0.587 + $B*0.114")
if [ "$(echo "$INTENSITY>186" | bc)" -eq 1 ]; then
TEXT_COLOR="#000000"
else
TEXT_COLOR="#FFFFFF"
fi
}
image_preview(){
case $IMAGE_VIEWER in
"mpv")
mpv --geometry=100x100 --title="Farge" "$FNAME" &>/dev/null &
;;
"feh")
feh --geometry=100x100 --title="Farge" "$FNAME" &>/dev/null &
;;
"sxiv")
sxiv -g=100x100 -b -N "Farge" "$FNAME" &>/dev/null &
;;
"imv")
imv "$FNAME" -s shrink &>/dev/null &
;;
*)
# If the image viewer given by the user is not supported by
# farge, then let the user know
echo "The image viewer $IMAGE_VIEWER is not supported yet."
echo "Make an issue requesting your image viewer: https://github.com/sdushantha/farge/issues/new"
;;
esac
}
main() {
if [ "$WAYLAND_DISPLAY" ]; then
HEX_COLOR=$(grim -g "$(slurp -p)" -t ppm - |
convert - -format '%[pixel:p{0,0}]' txt:- | tail -n1 |
grep '#' | awk '{print $3}')
else
HEX_COLOR=$(colorpicker -doq)
fi
# If no color is chosen, then exit
[[ ! $HEX_COLOR ]] && echo "No color was selected" && exit 1
mkdir -p $TEMP_DIR
# Remove the hashtag
HEX="${HEX_COLOR#\#}"
# Combine the dir and hex color code to form the file name
FNAME="$TEMP_DIR/$HEX.png"
hex_to_rgb "$HEX"
# If the baground is dark, then use white as the text color.
# If the background is light, then use a dark text color.
calculate_text_color
# Create a 100x100 image, filled with the selected color
convert -size 100x100 xc:"$HEX_COLOR" "$FNAME"
if [ $COLOR_TYPE == "rgb" ]; then
COLOR_CODE="($R,$G,$B)"
else
COLOR_CODE="$HEX_COLOR"
fi
if [ $WRITE_COLOR_CODE == true ]; then
# Write the color code in the center of the image
convert "$FNAME" -gravity Center -pointsize 10 -fill "$TEXT_COLOR" -annotate 0 "$COLOR_CODE" "$FNAME"
fi
# Save the color code to clipboard
if [ "$WAYLAND_DISPLAY" ]; then
printf %s "$COLOR_CODE" | wl-copy
else
printf %s "$COLOR_CODE" | xclip -sel c
fi
# Output the color code to stdout only if the user uses the --stdout flag
if [ "$STDOUT" == true ]; then
echo "$COLOR_CODE"
elif [ "$NOTIFICATION" == "true" ]; then
notify-send -a Farge "$COLOR_CODE" --icon="$FNAME" --expire-time="$EXPIRE_TIME"
elif [ "$PREVIEW" == "true" ]; then
image_preview
fi
}
while [[ "$1" ]]; do
case "$1" in
-h|--help) show_help && exit ;;
-v|--version) echo $VERSION && exit ;;
--no-preview) PREVIEW=false ;;
--no-color-code) WRITE_COLOR_CODE=false ;;
--rgb) COLOR_TYPE="rgb" ;;
--image-viewer) IMAGE_VIEWER="$2" ;;
--notify) NOTIFICATION=true ;;
--expire-time) EXPIRE_TIME="$2" ;;
--stdout) STDOUT=true ;;
esac
shift
done
# If the user wants to show a notification, then the color code
# will not be written onto the image because the color code will be
# shown in the notification message
[ "$NOTIFICATION" == true ] && WRITE_COLOR_CODE=false
check_dependencies
# When the user runs farge for the first time, tell them how to exit feh.
# We do with by checking if $MSG exists
[ ! -f "$MSG" ] && echo "To close the color window, click on it and press 'q'" && touch "$MSG"
# Run the main function where all the magic happens
main

View File

@ -1,334 +0,0 @@
#!/usr/bin/env sh
#
# by Siddharth Dushantha 2020
#
# Dependencies: jq, curl, w3m
#
VERSION=1.1.7
# By default 'tmpmail' uses 'w3m' as it's web browser to render
# the HTML of the email
BROWSER="w3m"
# If the value is set to 'true' tmpmail will convert the HTML email
# to raw text and send that to stdout
RAW_TEXT=false
# Everything related to 'tmpmail' will be stored in /tmp/tmpmail
# so that the old emails and email addresses get cleared after
# restarting the computer
TMPMAIL_DIR="/tmp/tmpmail"
# TMPMAIL_EMAIL_ADDRESS is where we store the temporary email address
# that gets generated. This prevents the user from providing
# the email address everytime they run tmpmail
TMPMAIL_EMAIL_ADDRESS="$TMPMAIL_DIR/email_address"
# tmpmail.html is where the email gets stored.
# Even though the file ends with a .html extension, the raw text version of
# the email will also be stored in this file so that w3m and other browsers
# are able to open this file
TMPMAIL_HTML_EMAIL="$TMPMAIL_DIR/tmpmail.html"
# Default 1secmail API URL
TMPMAIL_API_URL="https://www.1secmail.com/api/v1/"
usage() {
# Using 'cat << EOF' we can easily output a multiline text. This is much
# better than using 'echo' for each line or using '\n' to create a new line.
cat <<EOF
tmpmail
tmpmail -h | --version
tmpmail -g [ADDRESS]
tmpmail [-t | -b BROWSER] -r | ID
When called with no option and no argument, tmpmail lists the messages in
the inbox and their numeric IDs. When called with one argument, tmpmail
shows the email message with specified ID.
-b, --browser BROWSER
Specify BROWSER (default: w3m) that is used to render the HTML of
the email
-g, --generate [ADDRESS]
Generate a new email address, either the specified ADDRESS, or
randomly create one
-h, --help
Show help
-r, --recent
View the most recent email message
-t, --text
View the email as raw text, where all the HTML tags are removed.
Without this option, HTML is used.
--version
Show version
EOF
}
generate_email_address() {
# There are 2 ways which this function is called in this script.
# [1] The user wants to generate a new email and runs 'tmpmail --generate'
# [2] The user runs 'tmpmail' to check the inbox , but /tmp/tmpmail/email_address
# is empty or nonexistant. Therefore a new email gets automatically
# generated before showing the inbox. But of course the inbox will
# be empty as the newly generated email address has not been
# sent any emails.
#
# When the function 'generate_email_address()' is called with the arguement
# 'true', it means that the function was called because the user
# ran 'tmpmail --generate'.
#
# We need this variable so we can know whether or not we need to show the user
# what the email was. <-- More about this can be found further down in this function.
EXTERNALLY=${1:-false}
# This variable lets generate_email_address know if the user has provided a custom
# email address which they want to use. CUSTOM is set to false if $2 has no value.
CUSTOM=${2:-false}
# Generate a random email address.
# This function is called whenever the user wants to generate a new email
# address by running 'tmpmail --generate' or when the user runs 'tmpmail'
# but /tmp/tmpmail/email_address is empty or nonexistent.
#
# We create a random username by taking the first 10 lines from /dev/random
# and delete all the characters which are *not* lower case letters from A to Z.
# So charcters such as dashes, periods, underscore, and numbers are all deleted,
# giving us a text which only contains lower case letters form A to Z. We then take
# the first 10 characters, which will be the username of the email address
USERNAME=$(head /dev/urandom | LC_ALL=C tr -dc "[:alnum:]" | cut -c1-11 | tr "[:upper:]" "[:lower:]")
DOMAINS="1secmail.com 1secmail.net 1secmail.org esiix.com wwjmp.com"
# Randomly pick one of the domains mentiond above.
DOMAIN=$(printf "%b" "$DOMAINS" | tr " " "\n" | randomize | tail -1)
EMAIL_ADDRESS="$USERNAME@$DOMAIN"
# If the user provided a custom email address then use that email address
if [ "$CUSTOM" != false ]; then
EMAIL_ADDRESS=$CUSTOM
# Do a regex check to see if the email address provided by the user is a
# valid email address
REGEXP="[a-z0-9]+@(1secmail\.(com|net|org)|esiix.co|wwjmp.com)"
if ! printf %b "$EMAIL_ADDRESS" | grep -Eq "$REGEXP"; then
print_error "Provided email is invalid. Must match $REGEXP"
fi
fi
# Save the generated email address to the $TMPMAIL_EMAIL_ADDRESS file
# so that it can be whenever 'tmpmail' is run
printf %s "$EMAIL_ADDRESS" >"$TMPMAIL_EMAIL_ADDRESS"
# If this function was called because the user wanted to generate a new
# email address, show them the email address
[ "$EXTERNALLY" = true ] && cat "$TMPMAIL_EMAIL_ADDRESS" && printf "\n"
}
get_email_address() {
# This function is only called once and that is when this script
# get executed. The output of this function gets stored in $EMAIL_ADDRESS
#
# If the file that contains the email address is empty,
# that means we do not have an email address, so generate one.
[ ! -s "$TMPMAIL_EMAIL_ADDRESS" ] && generate_email_address
# Output the email address by getting the first line of $TMPMAIL_EMAIL
head -n 1 "$TMPMAIL_EMAIL_ADDRESS"
}
list_emails() {
# List all the received emails in a nicely formatted order
#
# Fetch the email data using 1secmail's API
DATA=$(curl -sL "$TMPMAIL_API_URL?action=getMessages&login=$USERNAME&domain=$DOMAIN")
# Using 'jq' we get the length of the JSON data. From this we can determine whether or not
# the email address has gotten any emails
DATA_LENGTH=$(printf %s "$DATA" | jq length)
# We are showing what email address is currently being used
# in case the user has forgotten what the email address was.
printf "[ Inbox for %s ]\n\n" "$EMAIL_ADDRESS"
# If the length of the data we got is 0, that means the email address
# has not received any emails yet.
[ "$DATA_LENGTH" -eq 0 ] && echo "No new mail" && exit
# This is where we store all of our emails, which is then
# displayed using 'column'
INBOX=""
# Go through each mail that has been received
index=1
while [ $index -le "${DATA_LENGTH}" ]; do
# Since arrays in JSON data start at 0, we must subtract
# the value of $index by 1 so that we dont miss one of the
# emails in the array
MAIL_DATA=$(printf %s "$DATA" | jq -r ".[$index-1]")
ID=$(printf %s "$MAIL_DATA" | jq -r ".id")
FROM=$(printf %s "$MAIL_DATA" | jq -r ".from")
SUBJECT=$(printf %s "$MAIL_DATA" | jq -r ".subject")
# The '||' are used as a divideder for 'column'. 'column' will use this divider as
# a point of reference to create the division. By default 'column' uses a blank space
# but that would not work in our case as the email subject could have multiple white spaces
# and 'column' would split the words that are seperated by white space, in different columns.
INBOX="$INBOX$ID ||$FROM ||$SUBJECT\n"
index=$((index + 1))
done
# Show the emails cleanly
printf "%b" "$INBOX" | column -t -s "||"
}
randomize() {
# We could use 'shuf' and 'sort -R' but they are not a part of POSIX
awk 'BEGIN {srand();} {print rand(), $0}' | \
sort -n -k1 | cut -d' ' -f2
}
view_email() {
# View an email by providing it's ID
#
# The first argument provided to this function will be the ID of the email
# that has been received
EMAIL_ID="$1"
DATA=$(curl -sL "${TMPMAIL_API_URL}?action=readMessage&login=$USERNAME&domain=$DOMAIN&id=$EMAIL_ID")
# After the data is retrieved using the API, we have to check if we got any emails.
# Luckly 1secmail's API is not complicated and returns 'Message not found' as plain text
# if our email address as not received any emails.
# If we received the error message from the API just quit because there is nothing to do
[ "$DATA" = "Message not found" ] && print_error "Message not found"
# We pass the $DATA to 'jq' which extracts the values
FROM=$(printf %s "$DATA" | jq -r ".from")
SUBJECT=$(printf %s "$DATA" | jq -r ".subject")
HTML_BODY=$(printf %s "$DATA" | jq -r ".htmlBody")
ATTACHMENTS=$(printf %s "$DATA" | jq -r ".attachments | length")
# If you get an email that is in pure text, the .htmlBody field will be empty and
# we will need to get the content from .textBody instead
[ -z "$HTML_BODY" ] && HTML_BODY="<pre>$(printf %s "$DATA" | jq -r ".textBody")</pre>"
# Create the HTML with all the information that is relevant and then
# assigning that HTML to the variable HTML_MAIL. This is the best method
# to create a multiline variable
HTML_MAIL=$(cat <<EOF
<pre><b>To: </b>$EMAIL_ADDRESS
<b>From: </b>$FROM
<b>Subject: </b>$SUBJECT</pre>
$HTML_BODY
EOF
)
if [ ! "$ATTACHMENTS" = "0" ]; then
HTML_MAIL="$HTML_MAIL<br><b>[Attachments]</b><br>"
index=1
while [ "$index" -le "$ATTACHMENTS" ]; do
FILENAME=$(printf %s "$DATA" | jq -r ".attachments | .[$index-1] | .filename")
LINK="$TMPMAIL_API_URL?action=download&login=$USERNAME&domain=$DOMAIN&id=$EMAIL_ID&file=$FILENAME"
HTML_LINK="<a href=$LINK download=$FILENAME>$FILENAME</a><br>"
if [ "$RAW_TEXT" = true ]; then
# The actual url is way too long and does not look so nice in STDOUT.
# Therefore we will shortening it using is.gd so that it looks nicer.
LINK=$(curl -s -F"url=$LINK" "https://is.gd/create.php?format=simple")
HTML_MAIL="$HTML_MAIL$LINK [$FILENAME]<br>"
else
HTML_MAIL="$HTML_MAIL$HTML_LINK"
fi
index=$((index + 1))
done
fi
# Save the $HTML_MAIL into $TMPMAIL_HTML_EMAIL
printf %s "$HTML_MAIL" >"$TMPMAIL_HTML_EMAIL"
# If the '--text' flag is used, then use 'w3m' to convert the HTML of
# the email to pure text by removing all the HTML tags
[ "$RAW_TEXT" = true ] && w3m -dump "$TMPMAIL_HTML_EMAIL" && exit
# Open up the HTML file using $BROWSER. By default,
# this will be 'w3m'.
$BROWSER "$TMPMAIL_HTML_EMAIL"
}
view_recent_email() {
# View the most recent email.
#
# This is done by listing all the received email like you
# normally see on the terminal when running 'tmpmail'.
# We then grab the ID of the most recent
# email, which the first line.
MAIL_ID=$(list_emails | head -3 | tail -1 | cut -d' ' -f 1)
view_email "$MAIL_ID"
}
print_error() {
# Print error message
#
# The first argument provided to this function will be the error message.
# Script will exit after printing the error message.
printf "%s\n" "Error: $1" >&2
exit 1
}
main() {
# Iterate of the array of dependencies and check if the user has them installed.
# We are checking if $BROWSER is installed instead of checking for 'w3m'. By doing
# this, it allows the user to not have to install 'w3m' if they are using another
# browser to view the HTML
for dependency in jq $BROWSER curl; do
if ! command -v "$dependency" >/dev/null 2>&1; then
print_error "Could not find '$dependency', is it installed?"
fi
done
# Create the $TMPMAIL_DIR directory and dont throw any errors
# if it already exists
mkdir -p "$TMPMAIL_DIR"
# Get the email address and save the value to the EMAIL_ADDRESS variable
EMAIL_ADDRESS="$(get_email_address)"
# ${VAR#PATTERN} Removes shortest match of pattern from start of a string.
# In this case, it takes the EMAIL_ADDRESS and removed everything after
# the '@' symbol which gives us the username.
USERNAME=${EMAIL_ADDRESS%@*}
# ${VAR%PATTERN} Remove shortest match of pattern from end of a string.
# In this case, it takes the EMAIL_ADDRESS and removes everything until the
# period '.' which gives us the domain
DOMAIN=${EMAIL_ADDRESS#*@}
# If no arguments are provided just the emails
[ $# -eq 0 ] && list_emails && exit
while [ "$1" ]; do
case "$1" in
--help | -h) usage && exit ;;
--generate | -g) generate_email_address true "$2" && exit ;;
--browser | -b) BROWSER="$2" ;;
--text | -t) RAW_TEXT=true ;;
--version) echo "$VERSION" && exit ;;
--recent | -r) view_recent_email && exit ;;
*[0-9]*)
# If the user provides number as an argument,
# assume its the ID of an email and try getting
# the email that belongs to the ID
view_email "$1" && exit
;;
-*) print_error "option '$1' does not exist" ;;
esac
shift
done
}
main "$@"

View File

@ -1,216 +0,0 @@
#!/usr/bin/env sh
#
# by Siddharth Dushantha
#
VERSION="1.0.0"
# Everything related to 'tmpsms' will be stored in this directory. Once the
# computer get restarted, this directory gets deleted.
TMPSMS_DIR="/tmp/tmpsms"
# The phone number that the user has selected gets stored in this file so that
# the do not have reselect at ever run.
TMPSMS_PHONE_NUMBER="$TMPSMS_DIR/phonenumber.txt"
# 'fzf' is used to allow the user to select a phone number. This variable
# stores extra arguments which the user might to provide, so that 'fzf'
# behaves to their liking.
FZF_ARGUMENTS=""
# The temporary SMS service is provided by Upmasked
API="https://upmasked.com"
usage(){
# Using 'cat << EOF' we can easily output a multiline text. This is much
# better than using 'echo' for each line or using '\n' to create a new line.
cat <<EOF
tmpsms [--count <count>]
tmpsms init [--fzf <arguments>]
tmpsms -h | --version
When called with no options or commands, tmpsms lists
the 3 newest messages.
Options
-h, --help Show this help message
-c, --count Only show the <count> newest messages
--version Show version
Commands
init Initialize a new phone number by selecting one
from the available ones using 'fzf'
--fzf Extra arguments to use for 'fzf'
EOF
}
print_error(){
# Print error message
#
# The first argument provided to this function will be the error message.
# Script will exit after printing the error message.
printf "%s\n" "Error: $1" >&2
exit 1
}
select_phone_number(){
# There are 2 ways which this function is called in this script.
# [1] The user wants to initilize a new phone number by running 'tmpsms init'
# [2] The user runs 'tmpsms' to check for new messages, but $TMPSMS_PHONE_NUMBER
# does't exist. Therefore they have to select phone number before we can
# show them the messages.
#
# When the function 'select_phone_number()' is called with the argument 'true'
# that means this function was called becaues the user ran 'tmpsms init'
#
# We need this variable so we can know whether or not we need to show the user
# the phone number they have selected. If they ran 'tmpsms init', then we will
# show them the phone number they selected. This is so that they can easily
# copy and paste it to whatever site that needs the phone number.
EXTERNALLY=${1:-false}
# Fetch the available phone numbers
DATA=$(curl -s "$API/api/sms/numbers")
# Using 'jq' we are able to get the length of the JSON data retreived from
# API. The length indicates the the total number of phone numbers available.
DATA_LENGTH=$(printf %s "$DATA" | jq length)
# This is where we store the phone numbers which then gets shown to the user
# through 'fzf' so that they can select one.
PHONE_NUMBERS=""
index=1
while [ $index -le "$DATA_LENGTH" ]; do
# Since arrays in JSON data start at 0, we must subtract
# the value of $index by 1 so that we dont miss one of the
# phone numbers in the array
PHONE_NUMBER_INFO=$(printf %s "$DATA" | jq -r ".[$index-1]")
PHONE_NUMBER=$(printf %s "$PHONE_NUMBER_INFO" | jq -r ".number")
COUNTRY_CODE=$(printf %s "$PHONE_NUMBER_INFO" | jq -r ".country")
PHONE_NUMBERS="$PHONE_NUMBERS$COUNTRY_CODE +$PHONE_NUMBER\n"
index=$((index+1))
done
# By default we use 'fzf' without any arguments in order to display the
# phone numbers they can use. If the '--fzf' argument is passed along with
# 'fzf' arguments, 'tmpsms' will make sure to use them.
FZF_COMMAND="fzf"
[ -n "$FZF_ARGUMENTS" ] && FZF_COMMAND="fzf $FZF_ARGUMENTS"
# If the user did not select a phone number then quit 'tmpsms' as the
# user might have just wanted to check if there were any new number
# that they could use.
SELECTION=$(printf %b "$PHONE_NUMBERS" | $FZF_COMMAND)
[ -z "$SELECTION" ] && print_error "Phone number was not selected"
# Store the selected phone number in $TMPSMS_PHONE_NUMBER for later use
printf %s "$SELECTION" > "$TMPSMS_PHONE_NUMBER"
# If the user ran 'tmpsms init', then show them their selection
[ "$EXTERNALLY" = true ] && printf "%s\n" "$SELECTION"
}
list_messages(){
# By default, the 3 newest messages are shown. But if the user would like
# to see more of the messages, they can provide how many they want to see
# by using the '--count' option.
COUNT="${1:-3}"
# The provided value to '--count' must be an interger. We can verify that it is
# an integer by checking if $COUNT matches the regex.
REGEX='^[0-9]+$'
if ! printf %s "$COUNT" | grep -Eq "$REGEX";then
print_error "'$COUNT' is not an integer"
fi
# If /tmp/tmpsms/phonenumber.txt does not exist or is empty that means that
# the user has not initialized a phone number yet.
[ ! -s "$TMPSMS_PHONE_NUMBER" ] && print_error "A phone number must be initilzied in order to view the messages"
# The country code is needed because it gets displayed to the user. It may
# be useful for the user to know which country the phone number is from
# so that they dont have to guess by looking at the area code.
COUNTRY_CODE=$(awk -F" " '{print $1}' < $TMPSMS_PHONE_NUMBER)
PHONE_NUMBER=$(awk -F"+" '{print $2}' < $TMPSMS_PHONE_NUMBER)
DATA=$(curl -s "$API/api/sms/messages/$PHONE_NUMBER")
# Even though we are using the phone numbers that are available on
# upmasked.com, there is a chance that they might remove one of the numbers.
# The checking needs to be done in case the phone number that is stored in
# $TMPSMS_PHONE_NUMBER has been removed.
if printf %s "$DATA" | grep -Eq "Not Found"; then
print_error "Looks like the phone number '+$PHONE_NUMBER' no longer exists. Initialize a new one and try again."
fi
DATA_LENGTH=$(printf %s "$DATA" | jq length)
# If the number of messages the user wants to view is greater than the
# number of messages that are available, then make sure to show
# all the messages that are available.
[ "$COUNT" -gt "$DATA_LENGTH" ] && COUNT="$DATA_LENGTH"
# Show a nice little header before showing the messages
printf "%s\n\n" "[ Messages for +$PHONE_NUMBER ($COUNTRY_CODE) ]"
# All the messages get stored in here
MESSAGES=""
index=1
while [ $index -le "$COUNT" ]; do
# Since arrays in JSON data start at 0, we must subtract
# the value of $index by 1 so that we dont miss one of the
# messages in the array
MESSAGE_DATA=$(printf %s "$DATA" | jq -r ".[$index-1]")
BODY=$(printf %s "$MESSAGE_DATA" | jq -r ".body" | tr "\n" " ")
SENDER=$(printf %s "$MESSAGE_DATA" | jq -r ".originator")
# The '||' is used as a divider for 'column'. 'column' will use this
# divider as a point of reference to create the division. By default
# 'column' uses a blank space but that would not work in our case as the
# message could have multiple white spaces and 'column' would
# split the words that are seperated by white space, in different columns.
MESSAGES="$MESSAGES$SENDER ||$BODY\n"
index=$((index+1))
done
# Show the messages cleanly
printf "%b" "$MESSAGES" | column -t -s "||"
}
main(){
# Iterate the array of dependencies and check if the user has them installed.
for dependency in jq curl fzf; do
if ! command -v "$dependency" >/dev/null 2>&1; then
print_error "Could not find '$dependency', is it installed?"
fi
done
# Create the $TMPSMS_DIR directory and dont throw any errors
# if it already exists
mkdir -p "$TMPSMS_DIR"
# If no arguments are provided just show the messages
[ $# -eq 0 ] && list_messages && exit 0
while [ "$1" ]; do
case "$1" in
init)
case "$2" in
--fzf) FZF_ARGUMENTS="$3" && select_phone_number true ;;
"") select_phone_number true ;;
esac ;;
--help | -h) usage && exit ;;
--count | -c) list_messages "$2" && shift 2;;
--version) printf %s "$VERSION" && exit ;;
-*) print_error "option '$1' does not exist" ;;
*) print_error "command '$1' does not exist" ;;
esac
shift
done
}
main "$@"

View File

@ -6,9 +6,9 @@
# yt search query takes input from the passed arg, prompts using fzf # yt search query takes input from the passed arg, prompts using fzf
# yt -r takes input and prompts using rofi ($guicmd) # yt -r takes input and prompts using rofi ($guicmd)
agent="Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0"
defcmd="fzf" defcmd="fzf"
guicmd="wofi -d -i" #uncomment next line for dmenu guicmd="wofi -d -i"
#guicmd="dmenu -i -l 15"
promptcmd="$defcmd" promptcmd="$defcmd"
if [ -z "$*" ]; then if [ -z "$*" ]; then
echo -n "Search: " echo -n "Search: "
@ -30,7 +30,7 @@ query=$(sed \
<<< "$query") <<< "$query")
# fetch the results with the $query and # fetch the results with the $query and
# delete all escaped characters # delete all escaped characters
response="$(curl -s "https://www.youtube.com/results?search_query=$query" |\ response="$(curl -s "https://www.youtube.com/results?search_query=$query" -A "$agent" |\
sed 's|\\.||g')" sed 's|\\.||g')"
# if unable to fetch the youtube results page, inform and exit # if unable to fetch the youtube results page, inform and exit
if ! grep -q "script" <<< "$response"; then echo "unable to fetch yt"; exit 1; fi if ! grep -q "script" <<< "$response"; then echo "unable to fetch yt"; exit 1; fi

13
setup/scripts.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
curl -fL "https://github.com/sdushantha/tmpsms/raw/master/tmpsms" -o $HOME/.local/bin/tmpsms
chmod 755 $HOME/.local/bin/tmpsms
curl -fL "https://github.com/sdushantha/tmpmail/raw/master/tmpmail" -o $HOME/.local/bin/tmpmail
chmod 755 $HOME/.local/bin/tmpmail
curl -fL "https://github.com/sdushantha/farge/raw/master/farge" -o $HOME/.local/bin/farge
chmod 755 $HOME/.local/bin/farge
curl -fL "https://raw.githubusercontent.com/Bugswriter/tuxi/main/tuxi" -o $HOME/.local/bin/tuxi
chmod 755 $HOME/.local/bin/tuxi