Browse Source

lazy update

master
John ShaggyTwoDope Jenkins 4 years ago
parent
commit
1b5993dac1
5 changed files with 331 additions and 3 deletions
  1. 113
    0
      drandr.rb
  2. 24
    0
      mega-dl.sh
  3. 188
    0
      termage
  4. 1
    1
      updatecalcurse
  5. 5
    2
      xkcd

+ 113
- 0
drandr.rb View File

@@ -0,0 +1,113 @@
#!/usr/bin/ruby -w

$DMENU_ARGS = ARGV.join(' ') + '-i -b'

class String
def starts_with? prefix
prefix = prefix.to_s
self[0, prefix.length] == prefix
end
end

def display prompt, *items
result = %x{echo "#{items.join "\n"}" | dmenu #{$DMENU_ARGS} -p '#{prompt}'}
if $? != 0
exit
end

if block_given?
yield result
else
return result
end
end

def query_xrandr *args
lines = %x{xrandr #{args.join ' '}}.split $/
if block_given?
yield lines
else
return lines
end
end

def get_outputs
query_xrandr '-q' do |lines|
lines.delete_at 0
lines.delete_if {|line| line.starts_with? ' '}
lines.map! {|line| line.split[0]}
if block_given?
yield lines
else
return lines
end
end
end

def get_output_info output
query_xrandr '-q' do |lines|
output_found = false
lines.delete_at 0
lines.reject! do |line|
if output_found
if line.starts_with? ' '
false
else
output_found = false
true
end
else
if line.starts_with? output
output_found = true
true
else
true
end
end
end
lines.map!{|line| line.split(' ').join(' ')}
if block_given?
yield lines
else
return lines
end
end
end


def main
display 'Choose an action', %w{Connect Disconnect Resize Rotate Move List} do |command|
case
when command == 'Connect'
display 'Connect which output?', get_outputs do |output|
end
when command == 'Disconnect'
display 'Disconnect which output?', get_outputs do |output|
query_xrandr '--output', output, '--off'
end
when command == 'Resize'
display 'Resize which output?', get_outputs do |output|
end
when command == 'Rotate'
display 'Rotate which output?', get_outputs do |output|
end
when command == 'Move'
display 'Move which output?', get_outputs do |output|
end
when command == 'List'
display 'Available outputs:', get_outputs do |output|
get_output_info output do |info|
resolutions = info.map {|line| line.split(' ')[0]}
display "#{output} resolutions:", resolutions do |resolution|
res_line = info.select {|line| line.starts_with? resolution}[0]
refresh_rates = res_line.split ' '
refresh_rates.delete_at(0)
display "#{output}@#{resolution} refresh rates:", refresh_rates
end
end
end
end
end
end

main

+ 24
- 0
mega-dl.sh View File

@@ -0,0 +1,24 @@
#!/bin/bash

if [[ $# != 2 ]]; then
echo "usage: mega-dl.sh <url> <output>"
exit 1
fi

url="$1"
enc_file="$2.enc"
out_file="$2"

id=`echo $url | awk -F '!' '{print $2}'`
key=`echo $url | awk -F '!' '{print $3}' | sed -e 's/-/+/g' -e 's/_/\//g' -e 's/,//g'`
b64_hex_key=`echo -n $key | base64 --decode --ignore-garbage 2> /dev/null | xxd -p | tr -d '\n'`
key[0]=$(( 0x${b64_hex_key:00:16} ^ 0x${b64_hex_key:32:16} ))
key[1]=$(( 0x${b64_hex_key:16:16} ^ 0x${b64_hex_key:48:16} ))
key=`printf "%x" ${key[*]}`
iv="${b64_hex_key:32:16}0000000000000000"
response=`curl --silent --request POST --data-binary '[{"a":"g","g":1,"p":"'$id'"}]' https://eu.api.mega.co.nz/cs`
echo "$response"
new_url=`echo "$response" | awk -F '"' '{print $10}'`
curl --output "$enc_file" "$new_url"
openssl enc -d -aes-128-ctr -K $key -iv $iv -in "$enc_file" -out "$out_file"
rm -f "$enc_file"

+ 188
- 0
termage View File

@@ -0,0 +1,188 @@
#!/bin/bash
VER="1.2"
LAST_UPDATED="December 5, 2014"
# This is a wrapper of the wrapper that z3bra made for w3mimgdisplay ( http://blog.z3bra.org/2014/01/images-in-terminal.html ).

# Keybinds
KILL="q" # Quit out from termage
PREV="n" # Go to the previous image
NEXT="o" # Go to the next image
REDRAW="r" # Redraw the current image
INFO="i" # Print the information of an image
TOGDUAL="d" # Toggle dual image mode.

# SETTINGS
FONTH=13 # Size of one terminal row
FONTW=8 # Size of one terminal column
IMGDISPLAY="/usr/lib/w3m/w3mimgdisplay" # The location of w3mimgdisplay


# Colours
BLACK="\033[0m\033[30m"
RED="\033[0m\033[31m"
GREEN="\033[0m\033[32m"
YELLOW="\033[0m\033[33m"
BLUE="\033[0m\033[34m"
MAGENTA="\033[0m\033[35m"
CYAN="\033[0m\033[36m"
WHITE="\033[0m\033[37m"

# Test for optional params
DUAL=0
QUIT=0
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
# Help command
echo -en "$WHITE"
echo "termage Version $VER"
echo "Last updated ${LAST_UPDATED}."
echo ""
echo "USE"
echo " termage FILE: Display FILE in the terminal."
echo " termage [-h | --help]: Display this message"
echo " termage [-d | --dual] FILE: Displays two images next to each other."
echo " * If there is only one image selected, this command does nothing."
echo " termage [-q | --quit] FILE: End Termage after printing the first image."
echo ""
echo "HOTKEYS"
echo " $KILL: Kill termage"
echo " $PREV: Go to the previous image (when more then one image is loaded)."
echo " $NEXT: Go to the next image (when more then one image is loaded)."
echo " $REDRAW: Redraw the current image."
echo " $INFO: Display information about the picture."
echo " $TOGDUAL: Toggle dual image view."
exit
elif [[ "$1" == "-d" ]] || [[ "$1" == "--dual" ]]; then
DUAL=1
shift
elif [[ "$1" == "-q" ]] || [[ "$1" == "--quit" ]]; then
QUIT=1
shift
fi

# Test the params for valid files.
IMG=0
FILE=()
k=0
echo -e "${WHITE}Loading selected files..."
for arg in "$@"; do
read h i <<< `echo -e "5;$arg" | $IMGDISPLAY`
echo $h | grep -Eq '[0-9]' || echo -e "$RED$arg"
echo $h | grep -Eq '[0-9]' || continue
echo -e "$GREEN$arg"
FILE[k]=$arg
k=`expr $k + 1`
done
echo -e "${WHITE}Loaded all files."

if [[ ${FILE[$IMG]} == "" ]]; then
echo -e "${RED}Error: No valid files."
exit
fi


# Functions
fnDispImg()
{

W=$1 # width
H=$2 # height
MW=$3 # max width
MH=$4 # max height
FN=$5 # font height
ID=$6 # image display
D=$7 # number
FH=$8 # Font height
if test $W -gt $MW; then
H=$(($H * $MW / $W))
W=$MW
fi
if test $H -gt $MH; then
W=$(($W * $MH / $H))
H=$MH
fi

COMMANDS="0;1;$((MW * D));0;$W;$H;;;;;$FN\n4;\n3;"
tput cup $(($MH/$FH)) 0
echo -en $COMMANDS|$ID
}


# Begin Image display loop
while true; do
clear
FILENAME=${FILE[$IMG]}
COLUMNS=`tput cols`
LINES=`tput lines`

read width height <<< `echo -e "5;$FILENAME" | $IMGDISPLAY`
im_width=$width
im_height=$height
max_width=$(($FONTW * $COLUMNS))
max_height=$(($FONTH * $(($LINES - 2))))
# if dual mode enabled split the maximum width in half
if [[ "$DUAL" == 1 ]]; then
max_width=$(($max_width / 2))
fi
# display the image
fnDispImg $width $height $max_width $max_height $FILENAME $IMGDISPLAY 0 $FONTH
#if dual mode is enabled display the second image
if [[ "$DUAL" == 1 ]]; then
IMG2=`expr $IMG + 1`
IMG2=`expr $IMG2 % ${#FILE[@]}`
FILENAME2=${FILE[IMG2]}
read width2 height2 <<< `echo -e "5;$FILENAME2" | $IMGDISPLAY`
im_width2=$width2
im_height2=$height2
fnDispImg $width2 $height2 $max_width $max_height $FILENAME2 $IMGDISPLAY 1 $FONTH
fi
# If the -q param was passed quit out of termage
if [[ "$QUIT" == 1 ]]; then
exit
fi
# Wait for and respond to key strokes
if [ -t 0 ]; then stty -echo -icanon time 0 min 0; fi
KEYPRESS=''
while true; do
read KEYPRESS
case $KEYPRESS in
$KILL) # Kill termage
exit;;
$PREV) # Previous image (changes to deal with dual image)
if [[ "$DUAL" = 0 ]]; then
IMG=`expr $IMG - 1`
else
IMG=`expr $IMG - 2`
fi; break;;
$NEXT) # Next image (changes to deal with dual image)
if [[ "$DUAL" = 0 ]]; then
IMG=`expr $IMG + 1`
else
IMG=`expr $IMG + 2`
fi; break;;
$REDRAW) # redraws the current image
break;;
$INFO) # Prints the info on the image (changes to deal with dual image)
clear
echo -en "$WHITE"
echo "$FILENAME"
echo "${im_width}x${im_height}"
if [[ "$DUAL" = 1 ]]; then
echo "-----------------------------------------"
echo "$FILENAME2"
echo "${im_width2}x${im_height2}"
fi;;
$TOGDUAL) # Toggles dual mode
if [[ "$DUAL" = 0 ]]; then
DUAL=1
else
DUAL=0
fi; break;;
*);;
esac
done
IMG=`expr $IMG % ${#FILE[@]}`
done

+ 1
- 1
updatecalcurse View File

@@ -3,7 +3,7 @@
# FILE: updatecalcurse
# ROLE: TODO (some explanation)
# CREATED: 2014-12-21 18:17:01
# MODIFIED: 2015-01-11 05:50:55
# MODIFIED: 2015-02-22 03:56:11

function check {
if (( $(pidof calcurse | wc -w) == 1 )); then

+ 5
- 2
xkcd View File

@@ -3,7 +3,7 @@
# FILE: xkcd
# ROLE: TODO (some explanation)
# CREATED: 2014-12-21 18:17:01
# MODIFIED: 2014-12-21 19:22:32
# MODIFIED: 2015-02-24 22:45:02



@@ -14,6 +14,9 @@ wget -qO- xkcd.com | grep -Po '(?<=")http://imgs[^/]+/comics/[^"]+\.\w{3}' > .xk
text() {
wget -qO- xkcd.com|tee |grep -Po '(?<=(\w{3})" title=").*(?=" alt)' > ~/.xkcd.text
}
cleantext() {
sed -i "s/&#39;/'/g" .xkcd.text
}

textshow() {
cat ~/.xkcd.text
@@ -21,7 +24,7 @@ cat ~/.xkcd.text

img
text
cleantext

textshow && sleep 10s && imgt ~/.xkcd.img


Loading…
Cancel
Save