Browse Source

lazy update

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 @@
1
+#!/usr/bin/ruby -w
2
+
3
+$DMENU_ARGS = ARGV.join(' ') + '-i -b'
4
+
5
+class String
6
+  def starts_with? prefix
7
+    prefix = prefix.to_s
8
+    self[0, prefix.length] == prefix
9
+  end
10
+end
11
+
12
+def display prompt, *items
13
+  result = %x{echo "#{items.join "\n"}" | dmenu #{$DMENU_ARGS} -p '#{prompt}'}
14
+  if $? != 0
15
+    exit
16
+  end
17
+
18
+  if block_given?
19
+    yield result
20
+  else
21
+    return result
22
+  end
23
+end
24
+
25
+def query_xrandr *args
26
+  lines = %x{xrandr #{args.join ' '}}.split $/
27
+  if block_given?
28
+    yield lines
29
+  else
30
+    return lines
31
+  end
32
+end
33
+
34
+def get_outputs
35
+  query_xrandr '-q' do |lines|
36
+    lines.delete_at 0
37
+    lines.delete_if {|line| line.starts_with? ' '}
38
+    lines.map! {|line| line.split[0]}
39
+    if block_given?
40
+      yield lines
41
+    else
42
+      return lines
43
+    end
44
+  end
45
+end
46
+
47
+def get_output_info output
48
+  query_xrandr '-q' do |lines|
49
+    output_found = false
50
+    lines.delete_at 0
51
+    lines.reject! do |line|
52
+      if output_found
53
+        if line.starts_with? ' '
54
+          false
55
+        else
56
+          output_found = false
57
+          true
58
+        end
59
+      else
60
+        if line.starts_with? output
61
+          output_found = true
62
+          true
63
+        else
64
+          true
65
+        end
66
+      end
67
+    end
68
+    lines.map!{|line| line.split(' ').join(' ')}
69
+    if block_given?
70
+      yield lines
71
+    else
72
+      return lines
73
+    end
74
+  end
75
+end
76
+
77
+
78
+def main
79
+  display 'Choose an action', %w{Connect Disconnect Resize Rotate Move List} do |command|
80
+    case
81
+    when command == 'Connect'
82
+      display 'Connect which output?', get_outputs do |output|
83
+      end
84
+    when command == 'Disconnect'
85
+      display 'Disconnect which output?', get_outputs do |output|
86
+        query_xrandr '--output', output, '--off'
87
+      end
88
+    when command == 'Resize'
89
+      display 'Resize which output?', get_outputs do |output|
90
+      end
91
+    when command == 'Rotate'
92
+      display 'Rotate which output?', get_outputs do |output|
93
+      end
94
+    when command == 'Move'
95
+      display 'Move which output?', get_outputs do |output|
96
+      end
97
+    when command == 'List'
98
+      display 'Available outputs:', get_outputs do |output|
99
+        get_output_info output do |info|
100
+          resolutions = info.map {|line| line.split(' ')[0]}
101
+          display "#{output} resolutions:", resolutions do |resolution|
102
+            res_line = info.select {|line| line.starts_with? resolution}[0]
103
+            refresh_rates = res_line.split ' '
104
+            refresh_rates.delete_at(0)
105
+            display "#{output}@#{resolution} refresh rates:", refresh_rates
106
+          end
107
+        end
108
+      end
109
+    end
110
+  end
111
+end
112
+
113
+main

+ 24
- 0
mega-dl.sh View File

@@ -0,0 +1,24 @@
1
+#!/bin/bash
2
+
3
+if [[ $# != 2 ]]; then 
4
+    echo "usage: mega-dl.sh <url> <output>"
5
+    exit 1
6
+fi
7
+
8
+url="$1"
9
+enc_file="$2.enc"
10
+out_file="$2"
11
+
12
+id=`echo $url | awk -F '!' '{print $2}'`
13
+key=`echo $url | awk -F '!' '{print $3}' | sed -e 's/-/+/g' -e 's/_/\//g' -e 's/,//g'`
14
+b64_hex_key=`echo -n $key | base64 --decode --ignore-garbage 2> /dev/null | xxd -p | tr -d '\n'`
15
+key[0]=$(( 0x${b64_hex_key:00:16} ^ 0x${b64_hex_key:32:16} ))
16
+key[1]=$(( 0x${b64_hex_key:16:16} ^ 0x${b64_hex_key:48:16} ))
17
+key=`printf "%x" ${key[*]}`
18
+iv="${b64_hex_key:32:16}0000000000000000"
19
+response=`curl --silent --request POST --data-binary '[{"a":"g","g":1,"p":"'$id'"}]' https://eu.api.mega.co.nz/cs`
20
+echo "$response"
21
+new_url=`echo "$response" | awk -F '"' '{print $10}'`
22
+curl --output "$enc_file" "$new_url"
23
+openssl enc -d -aes-128-ctr -K $key -iv $iv -in "$enc_file" -out "$out_file"
24
+rm -f "$enc_file"

+ 188
- 0
termage View File

@@ -0,0 +1,188 @@
1
+#!/bin/bash
2
+VER="1.2"
3
+LAST_UPDATED="December 5, 2014"
4
+# This is a wrapper of the wrapper that z3bra made for w3mimgdisplay ( http://blog.z3bra.org/2014/01/images-in-terminal.html ).
5
+
6
+# Keybinds
7
+KILL="q" # Quit out from termage
8
+PREV="n" # Go to the previous image
9
+NEXT="o" # Go to the next image
10
+REDRAW="r" # Redraw the current image
11
+INFO="i" # Print the information of an image
12
+TOGDUAL="d" # Toggle dual image mode.
13
+
14
+# SETTINGS
15
+FONTH=13 # Size of one terminal row
16
+FONTW=8  # Size of one terminal column
17
+IMGDISPLAY="/usr/lib/w3m/w3mimgdisplay" # The location of w3mimgdisplay
18
+
19
+
20
+# Colours
21
+BLACK="\033[0m\033[30m"
22
+RED="\033[0m\033[31m"
23
+GREEN="\033[0m\033[32m"
24
+YELLOW="\033[0m\033[33m"
25
+BLUE="\033[0m\033[34m"
26
+MAGENTA="\033[0m\033[35m"
27
+CYAN="\033[0m\033[36m"
28
+WHITE="\033[0m\033[37m"
29
+
30
+# Test for optional params
31
+DUAL=0
32
+QUIT=0
33
+if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
34
+	# Help command
35
+	echo -en "$WHITE"
36
+	echo "termage Version $VER"
37
+	echo "Last updated ${LAST_UPDATED}."
38
+	echo ""
39
+	echo "USE"
40
+	echo "   termage FILE: Display FILE in the terminal."
41
+	echo "   termage [-h | --help]: Display this message"
42
+	echo "   termage [-d | --dual] FILE: Displays two images next to each other."
43
+	echo "      * If there is only one image selected, this command does nothing."
44
+	echo "   termage [-q | --quit] FILE: End Termage after printing the first image."
45
+	echo ""
46
+	echo "HOTKEYS"
47
+	echo "   $KILL: Kill termage"
48
+	echo "   $PREV: Go to the previous image (when more then one image is loaded)."
49
+	echo "   $NEXT: Go to the next image (when more then one image is loaded)."
50
+	echo "   $REDRAW: Redraw the current image."
51
+	echo "   $INFO: Display information about the picture."
52
+	echo "   $TOGDUAL: Toggle dual image view."
53
+	exit
54
+elif [[ "$1" == "-d" ]] || [[ "$1" == "--dual" ]]; then
55
+	DUAL=1
56
+	shift 
57
+elif [[ "$1" == "-q" ]] || [[ "$1" == "--quit" ]]; then
58
+	QUIT=1
59
+	shift
60
+fi
61
+
62
+# Test the params for valid files.
63
+IMG=0
64
+FILE=()
65
+k=0
66
+echo -e "${WHITE}Loading selected files..."
67
+for arg in "$@"; do
68
+       	read h i <<< `echo -e "5;$arg" | $IMGDISPLAY`
69
+	echo $h | grep -Eq '[0-9]' || echo -e "$RED$arg"
70
+	echo $h | grep -Eq '[0-9]' || continue
71
+	echo -e "$GREEN$arg"
72
+	FILE[k]=$arg
73
+	k=`expr $k + 1`
74
+done
75
+echo -e "${WHITE}Loaded all files."
76
+
77
+if [[ ${FILE[$IMG]} == "" ]]; then
78
+	echo -e "${RED}Error: No valid files."
79
+	exit
80
+fi
81
+
82
+
83
+# Functions
84
+fnDispImg()
85
+{
86
+
87
+	W=$1 # width
88
+	H=$2 # height
89
+	MW=$3 # max width
90
+	MH=$4 # max height
91
+	FN=$5 # font height
92
+	ID=$6 # image display
93
+	D=$7 # number
94
+	FH=$8 # Font height
95
+	if test $W -gt $MW; then
96
+		H=$(($H * $MW / $W))
97
+		W=$MW
98
+	fi
99
+	if test $H -gt $MH; then
100
+		W=$(($W * $MH / $H))
101
+		H=$MH
102
+	fi
103
+
104
+	COMMANDS="0;1;$((MW * D));0;$W;$H;;;;;$FN\n4;\n3;"
105
+	tput cup $(($MH/$FH)) 0 
106
+	echo -en $COMMANDS|$ID
107
+}
108
+
109
+
110
+# Begin Image display loop
111
+while true; do
112
+	clear
113
+	FILENAME=${FILE[$IMG]}
114
+	COLUMNS=`tput cols`
115
+	LINES=`tput lines`
116
+
117
+	read width height <<< `echo -e "5;$FILENAME" | $IMGDISPLAY`
118
+	im_width=$width
119
+	im_height=$height
120
+	max_width=$(($FONTW * $COLUMNS))
121
+	max_height=$(($FONTH * $(($LINES - 2))))
122
+	
123
+	# if dual mode enabled split the maximum width in half
124
+	if [[ "$DUAL" == 1 ]]; then
125
+		max_width=$(($max_width / 2))
126
+	fi
127
+	
128
+	# display the image
129
+	fnDispImg $width $height $max_width $max_height $FILENAME $IMGDISPLAY 0 $FONTH
130
+	#if dual mode is enabled display the second image
131
+	if [[ "$DUAL" == 1 ]]; then
132
+		IMG2=`expr $IMG + 1`
133
+		IMG2=`expr $IMG2 % ${#FILE[@]}`
134
+		FILENAME2=${FILE[IMG2]}
135
+		read width2 height2 <<< `echo -e "5;$FILENAME2" | $IMGDISPLAY`
136
+		im_width2=$width2
137
+		im_height2=$height2
138
+		fnDispImg $width2 $height2 $max_width $max_height $FILENAME2 $IMGDISPLAY 1 $FONTH
139
+	fi
140
+	
141
+	# If the -q param was passed quit out of termage
142
+	if [[ "$QUIT" == 1 ]]; then
143
+		exit
144
+	fi
145
+	
146
+	# Wait for and respond to key strokes
147
+	if [ -t 0 ]; then stty -echo -icanon time 0 min 0; fi
148
+	KEYPRESS=''
149
+	while true; do
150
+		read KEYPRESS
151
+		case $KEYPRESS in 
152
+			$KILL) # Kill termage
153
+				exit;;
154
+			$PREV) # Previous image (changes to deal with dual image)
155
+				if [[ "$DUAL" = 0 ]]; then
156
+					IMG=`expr $IMG - 1`
157
+				else
158
+					IMG=`expr $IMG - 2`
159
+				fi; break;;
160
+			$NEXT) # Next image (changes to deal with dual image)
161
+				if [[ "$DUAL" = 0 ]]; then
162
+					IMG=`expr $IMG + 1`
163
+				else
164
+					IMG=`expr $IMG + 2`
165
+				fi; break;;
166
+			$REDRAW) # redraws the current image 
167
+				break;;
168
+			$INFO) # Prints the info on the image (changes to deal with dual image)
169
+				clear
170
+				echo -en "$WHITE"
171
+				echo "$FILENAME"
172
+				echo "${im_width}x${im_height}"
173
+				if [[ "$DUAL" = 1 ]]; then
174
+					echo "-----------------------------------------"
175
+					echo "$FILENAME2"
176
+					echo "${im_width2}x${im_height2}"
177
+				fi;;
178
+			$TOGDUAL) # Toggles dual mode 
179
+				if [[ "$DUAL" = 0 ]]; then
180
+					DUAL=1
181
+				else
182
+					DUAL=0
183
+				fi; break;;
184
+			*);; 
185
+		esac
186
+	done
187
+	IMG=`expr $IMG % ${#FILE[@]}`
188
+done

+ 1
- 1
updatecalcurse View File

@@ -3,7 +3,7 @@
3 3
 # FILE:     updatecalcurse
4 4
 # ROLE:     TODO (some explanation)
5 5
 # CREATED:  2014-12-21 18:17:01
6
-# MODIFIED: 2015-01-11 05:50:55
6
+# MODIFIED: 2015-02-22 03:56:11
7 7
 
8 8
 function check {
9 9
 if (( $(pidof calcurse | wc -w) == 1 )); then 

+ 5
- 2
xkcd View File

@@ -3,7 +3,7 @@
3 3
 # FILE:     xkcd
4 4
 # ROLE:     TODO (some explanation)
5 5
 # CREATED:  2014-12-21 18:17:01
6
-# MODIFIED: 2014-12-21 19:22:32
6
+# MODIFIED: 2015-02-24 22:45:02
7 7
 
8 8
 
9 9
 
@@ -14,6 +14,9 @@ wget -qO- xkcd.com | grep -Po '(?<=")http://imgs[^/]+/comics/[^"]+\.\w{3}' > .xk
14 14
 text() {
15 15
 wget -qO- xkcd.com|tee |grep -Po '(?<=(\w{3})" title=").*(?=" alt)' > ~/.xkcd.text
16 16
 }
17
+cleantext() {
18
+    sed -i "s/&#39;/'/g" .xkcd.text
19
+}
17 20
 
18 21
 textshow() {
19 22
 cat ~/.xkcd.text
@@ -21,7 +24,7 @@ cat ~/.xkcd.text
21 24
 
22 25
 img
23 26
 text
24
-
27
+cleantext
25 28
 
26 29
 textshow && sleep 10s && imgt ~/.xkcd.img
27 30
 

Loading…
Cancel
Save