aboutsummaryrefslogtreecommitdiffstats
path: root/.zshrc-linux-desktop
blob: aee3aa5c15497e07122c5cbb572e03a178ae3eec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
################## FUNCTIONS ##################

# power off after finishing mpd playlist
mpc-sleep() {
	mpc play
	while true; do
		mpc status
		mpc idle player
		if [[ -z "$(mpc status | grep playing)" ]]; then
			poweroff
		fi
	done
}

# capture webm
scap() {
	archey3
	sleep .1
	if [[ -f '/tmp/out.webm' ]]; then
		rm /tmp/out.webm
	fi
	echo 'recording...'
	ffmpeg -video_size 1920x1080 -framerate 30 -f x11grab -i :0.0 \
		-c:v libvpx -b:v 4M -threads 4 /tmp/out.webm > /dev/null 2>&1
}

# quickly send a file to hosted tmp dir
send() {
	if [[ "$1" ]]; then
		scp $@ shmibbles.me:http/tmp/
		if [[ $? -eq 0 ]]; then
			for name in "$@"
			do
				basename=$(basename $name)
				ssh shmibbles.me "cd http/tmp; chmod o+r '$basename'"
				name=$(echo "http://shmibbles.me/tmp/$basename"\
				| sed 's/ /%20/g')
				echo $name | tr -d '\n' | xclip -i -selection clipboard
				echo $name | tr -d '\n' | xclip -i -selection primary
			done
		fi
	else
		echo "specify at least one file to send"
	fi
}

# take a screenshot, upload to /img/scrot, and update current symlink
ssh-scrot() {
	archey3

	if [[ "$1" != "" ]]; then
		name=$1
	else
		echo -n "name: "
		read name
	fi
	
	date=$(date +'%Y-%m-%d')
	
	folder="http/img/scrot"
	ssh shmibbles.me "mkdir -p $folder/$date"
	
	if [[ "${?#0}" != "" ]]; then
		return 1
	fi

	ssh shmibbles.me "rm $folder/current 2>/dev/null; ln -s $folder/$date $folder/current"
	
	for i in {3..1}; do
		echo -n "$i "
		sleep 1
	done
	
	echo 'cheese!'
	sleep .1

	scrot /tmp/$name.png
	convert -scale 250x /tmp/$name.png /tmp/${name}_small.png

	scp /tmp/$name.png /tmp/${name}_small.png shmibbles.me:http/img/scrot/$date

	echo "http://shmibbles.me/img/scrot/$date/$name.png" | tr -d '\n' | xclip -i -selection clipboard
	echo "http://shmibbles.me/img/scrot/$date/$name.png" | tr -d '\n' | xclip -i -selection primary
	echo "http://shmibbles.me/img/scrot/$date/${name}_small.png" | tr -d '\n' | xclip -i -selection clipboard
	echo "http://shmibbles.me/img/scrot/$date/${name}_small.png" | tr -d '\n' | xclip -i -selection primary

	echo 'sent!'

	rm /tmp/$name.png /tmp/${name}_small.png

}

# export a section of a video to gif
make-gif() {

	if [[ -z "$1" ]]; then
		break
	fi

	rm -f make-gif-palette.png
	rm -f make-gif-palette.png
	rm -f make-gif-in
	
	rm -f make-gif-in
	
	ln -s "$1" make-gif-in
	
	echo -n "start [00:00:00]: "
	read start
	if [[ -z "$start" ]]; then
		start="00:00:00"
	fi
	
	echo -n "length [full]: "
	read length
	if [[ -z "$length" ]]; then
		t=""
		length=""
	else
		t="-t"
	fi

	echo -n "fps [10]: "
	read fps
	if [[ -z "$fps" ]]; then
		fps="10"
	fi
	
	echo -n "width [480]: "
	read width
	if [[ -z "$width" ]]; then
		width="480"
	fi

	echo -n "use subtitles? [y/N]: "
	read subs
	if [[ "$subs" == "y" || "$subs" == "Y" ]]; then
		subs="true"
	else 
		subs=""
	fi
	
	if [[ $subs ]]; then
		ffmpeg -y -ss "$start" $t "$length" -i "$1" \
			-copyts -vf "subtitles=make-gif-in,fps=$fps,scale=$width:-1:flags=lanczos,palettegen" make-gif-palette.png
		ffmpeg -ss "$start" $t "$length" -i "$1" -i make-gif-palette.png \
			-copyts -filter_complex \
			"subtitles=make-gif-in,fps=$fps,scale=$width:-1:flags=lanczos[x];[x][1:v]paletteuse" \
			out.gif
	else
		ffmpeg -y -ss "$start" $t "$length" -i "$1" \
			-vf "fps=$fps,scale=$width:-1:flags=lanczos,palettegen" make-gif-palette.png
		ffmpeg -ss "$start" $t "$length" -i "$1" -i make-gif-palette.png -filter_complex \
			"fps=$fps,scale=$width:-1:flags=lanczos[x];[x][1:v]paletteuse" \
			out.gif
	fi

	rm -f make-gif-palette.png
	rm -f make-gif-in
}

# um...
fuck() {
	fuck="fuck"
	while true; do
		echo -en "\e[$((RANDOM%2));$((RANDOM%8+30))m"

		for i in {1..4}; do
			if [[ $((RANDOM%2)) -eq 1 ]]; then
				echo -n $fuck[$i] | tr '[:lower:]' '[:upper:]'
			else
				echo -n $fuck[$i]
			fi
		done

		for i in {1..$((RANDOM%20))}; do
			echo -n " "
		done
	done
}