functions 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. #!/bin/sh
  2. # In the name of Allah, the most Gracious, the most Merciful.
  3. #
  4. # ▓▓▓▓▓▓▓▓▓▓
  5. # ░▓ Author ▓ Abdullah <https://abdullah.today>
  6. # ░▓▓▓▓▓▓▓▓▓▓
  7. # ░░░░░░░░░░
  8. # ░█▀▀░█░█░█▀▀░█░░░█░░░░░█▀▀░█░█░█▀█░█▀▀░▀█▀░▀█▀░█▀█░█▀█░█▀▀
  9. # ░▀▀█░█▀█░█▀▀░█░░░█░░░░░█▀▀░█░█░█░█░█░░░░█░░░█░░█░█░█░█░▀▀█
  10. # ░▀▀▀░▀░▀░▀▀▀░▀▀▀░▀▀▀░░░▀░░░▀▀▀░▀░▀░▀▀▀░░▀░░▀▀▀░▀▀▀░▀░▀░▀▀▀
  11. function mkd {
  12. mkdir -p "$@" && cd "$_";
  13. }
  14. # for webm videos to mp4
  15. function webm2mp4 {
  16. for file in *.webm
  17. do
  18. ffmpeg -i "$file" "`basename "$file" .webm` .mp4"
  19. done
  20. }
  21. # mp4 to mp3
  22. function mp42mp3 {
  23. CURRENTMP4HERE=$(ls *.mp4 | wc -l)
  24. notify-send "Found $CURRENTMP4HERE mp4s, gonna convert them now, be patient"
  25. for file in *.mp4
  26. do
  27. ffmpeg -y -i "$file" "`basename "$file" .mp4`.mp3"
  28. done
  29. notify-send "All $CURRENTMP4HERE mp4s have been converted to mp3s and now we are moving them to your music dir"
  30. CURRENTMP3INMPD=$(ls $HOME/mus/*.mp3 | wc -l)
  31. notify-send "You have $CURRENTMP3INMPD mp3s in your database"
  32. mv *.mp3 ~/mus/ -v
  33. notify-send "All mp3s have been moved to music dir."
  34. TOTAL=$(($CURRENTMP3INMPD + $CURRENTMP4HERE))
  35. notify-send "You have got $CURRENTMP4HERE new mp3s. Now you have $TOTAL songs in database. Enjoy your music"
  36. }
  37. # mp3 to aac
  38. mp3toaac () {
  39. for file in *.mp3
  40. do
  41. ffmpeg -y -i "$file" "`basename "$file" .mp3`.aac"
  42. done
  43. }
  44. function speedup {
  45. base=$(basename $1)
  46. ext="${base##*.}"
  47. base="${base%.*}"
  48. ffmpeg -i $1 -filter:v "setpts=0.5*PTS" $base'_speed.'$ext
  49. notify-send "your video has got speed. Enjoy"
  50. }
  51. # aac + image = mp4
  52. aactomkv ()
  53. {
  54. for files in *.aac
  55. do
  56. ffmpeg -y -loop 1 -framerate 1/25 -i image.jpg -i "$file" -vf "scale='min(1280,iw)':-2, format=yuv420p" -c:v libx264 -preset veryslow -crf 0 -c:a copy "`basename "$file" .aac`.mkv"
  57. done
  58. }
  59. function hdimg () {
  60. # converts images into HD wallpapers 1920x1080
  61. # Accepts globbing as first argument e.g. jpg as first argument will convert all
  62. # jpgs into HD images and saves them into new dir resized in same directory
  63. ext="$1"
  64. mkdir resized 2>/dev/null
  65. for file in *."$ext"
  66. do
  67. convert $file -resize 1920x1080! resized/`basename $file .$ext`.$ext
  68. done
  69. }
  70. function mp3tomp4 ()
  71. # Makes youtube compliant mp4 from a image( must be a .jpg and its size should be a multiple of 2. Use imagemagic's identify to measure it `identify image.jpg`
  72. # if not a multiple of 2, `convert image.jpg -resize 1024x512! imag2.jpg`
  73. # Usage:
  74. # mp3tomp4 image.jpg audio.mp3 output.mp4
  75. {
  76. ffmpeg -loop 1 -r 1 -i $1 -i $2 -vcodec libx264 -acodec copy -shortest $3
  77. }
  78. function pl ()
  79. {
  80. mpc searchplay $1
  81. }
  82. function mergeaudio ()
  83. # Create a .txt file in same directory and add files to be merged there as "file file1 and on new line, file file2"
  84. # Usage:
  85. # mergeaudio files.txt output.mp3
  86. {
  87. ffmpeg -f concat -safe 0 -i $1 -c copy $2
  88. }
  89. function mergeaudiotovideo ()
  90. # maps audio with video, first arg should be video, second should be audio and
  91. # third should be the output
  92. {
  93. ffmpeg -i $1 -i $2 -c copy -map 0:v:0 -map 1:a:0 $3
  94. }
  95. # Jobs mail
  96. function apply {
  97. gpg -dq $HOME/bin/misc/job.gpg | mutt -s "Applying for Job" $1
  98. }
  99. # Encrypt a file to myself
  100. function ei {
  101. gpg -er C19D1580 $1
  102. }
  103. # Decrypt a file
  104. function di {
  105. gpg -do $1 $2
  106. }
  107. # Bakchod
  108. function bakchod {
  109. echo "$@" | tr a-zA-Z n-za-mN-ZA-M
  110. }
  111. # mail
  112. function alish {
  113. mutt -s Important bar <<<"$@";
  114. }
  115. # mailto
  116. function mailto {
  117. $TERMINAL -e mutt "$@"
  118. }
  119. function aa_256 ()
  120. {
  121. local o= i= x=`tput op` cols=`tput cols` y= oo= yy=;
  122. y=`printf %$(($cols-6))s`;
  123. yy=${y// /=};
  124. for i in {0..256};
  125. do
  126. o=00${i};
  127. oo=`echo -en "setaf ${i}\nsetab ${i}\n"|tput -S`;
  128. echo -e "${o:${#o}-3:3} ${oo}${yy}${x}";
  129. done
  130. }
  131. function aa_c666 ()
  132. {
  133. local r= g= b= c= CR="`tput sgr0;tput init`" C="`tput op`" n="\n\n\n" t=" " s=" ";
  134. echo -e "${CR}${n}";
  135. function c666 ()
  136. {
  137. local b= g=$1 r=$2;
  138. for ((b=0; b<6; b++))
  139. do
  140. c=$(( 16 + ($r*36) + ($g*6) + $b ));
  141. echo -en "setaf ${c}\nsetab ${c}\n" | tput -S;
  142. echo -en "${s}";
  143. done
  144. };
  145. function c666b ()
  146. {
  147. local g=$1 r=;
  148. for ((r=0; r<6; r++))
  149. do
  150. echo -en " `c666 $g $r`${C} ";
  151. done
  152. };
  153. for ((g=0; g<6; g++))
  154. do
  155. c666b=`c666b $g`;
  156. echo -e " ${c666b}";
  157. echo -e " ${c666b}";
  158. echo -e " ${c666b}";
  159. echo -e " ${c666b}";
  160. echo -e " ${c666b}";
  161. done;
  162. echo -e "${CR}${n}${n}"
  163. }
  164. ht() {
  165. a=$(cat); curl -X POST -s -d "$a" https://hastebin.com/documents | awk -F '"' '{print "https://hastebin.com/"$4}' | xclip ;
  166. }
  167. function fs() {
  168. if du -b /dev/null > /dev/null 2>&1; then
  169. local arg=-sbh;
  170. else
  171. local arg=-sh;
  172. fi
  173. if [[ -n "$@" ]]; then
  174. du $arg -- "$@";
  175. else
  176. du $arg .[^.]* ./*;
  177. fi;
  178. }
  179. function dataurl() {
  180. local mimeType=$(file -b --mime-type "$1");
  181. if [[ $mimeType == text/* ]]; then
  182. mimeType="${mimeType};charset=utf-8";
  183. fi
  184. echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')";
  185. }
  186. function escape() {
  187. printf "\\\x%s" $(printf "$@" | xxd -p -c1 -u);
  188. # print a newline unless we’re piping the output to another program
  189. if [ -t 1 ]; then
  190. echo ""; # newline
  191. fi;
  192. }
  193. function v() {
  194. if [ $# -eq 0 ]; then
  195. $EDITOR .;
  196. else
  197. $EDITOR "$@";
  198. fi;
  199. }
  200. function o() {
  201. if [ $# -eq 0 ]; then
  202. ranger .;
  203. else
  204. ranger "$@";
  205. fi;
  206. }
  207. function tre() {
  208. tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX;
  209. }
  210. ix() {
  211. local opts
  212. local OPTIND
  213. [ -f "$HOME/.netrc" ] && opts='-n'
  214. while getopts ":hd:i:n:" x; do
  215. case $x in
  216. h) echo "ix [-d ID] [-i ID] [-n N] [opts]"; return;;
  217. d) $echo curl $opts -X DELETE ix.io/$OPTARG; return;;
  218. i) opts="$opts -X PUT"; local id="$OPTARG";;
  219. n) opts="$opts -F read:1=$OPTARG";;
  220. esac
  221. done
  222. shift $(($OPTIND - 1))
  223. [ -t 0 ] && {
  224. local filename="$1"
  225. shift
  226. [ "$filename" ] && {
  227. curl $opts -F f:1=@"$filename" $* ix.io/$id
  228. return
  229. }
  230. echo "^C to cancel, ^D to send."
  231. }
  232. curl $opts -F f:1='<-' $* ix.io/$id
  233. }
  234. shebang() {
  235. if i=$(which $1);
  236. then
  237. printf '#!/usr/bin/env %s\n\n' $1 > $2 && chmod 755 $2 && vim + $2 && chmod 755 $2;
  238. else
  239. echo "'which' could not find $1, is it in your \$PATH?";
  240. fi;
  241. # in case the new script is in path, this throw out the command hash table and
  242. # start over (man zshbuiltins)
  243. rehash
  244. }
  245. function webcam () {
  246. mplayer -cache 128 -tv driver=v4l2:width=350:height=350 -vo xv tv:// -noborder -geometry "+1340+445" -ontop -quiet 2>/dev/null >/dev/null
  247. }
  248. function psg () {
  249. pass generate "$1" --clip
  250. cd ~/.password-store
  251. git push
  252. cd -
  253. }
  254. function weather() {
  255. curl wttr.in/"$1"
  256. }
  257. function cnsp () {
  258. sudo /etc/rc.d/crond stop
  259. sleep 1
  260. sudo /etc/rc.d/crond status
  261. }
  262. function cnst () {
  263. sudo /etc/rc.d/crond start
  264. sleep 1
  265. sudo /etc/rc.d/crond status
  266. }
  267. function ko () {
  268. a=$(cat)
  269. curl -X POST -s -d "raw:$a" http://kopy.io/documents | awk -F '"' '{print "http://kopy.io/"$4}'
  270. }
  271. function pb()
  272. {
  273. local url='https://paste.c-net.org/'
  274. if (( $# )); then
  275. local file
  276. for file; do
  277. curl -s \
  278. --data-binary @"$file" \
  279. --header "X-FileName: ${file##*/}" \
  280. "$url"
  281. done
  282. else
  283. curl -s --data-binary @- "$url"
  284. fi
  285. }
  286. function pg()
  287. {
  288. local url='https://paste.c-net.org/'
  289. if (( $# )); then
  290. local arg
  291. for arg; do
  292. curl -s "${url}${arg##*/}"
  293. done
  294. else
  295. local arg
  296. while read -r arg; do
  297. curl -s "${url}${arg##*/}"
  298. done
  299. fi
  300. }
  301. function ap()
  302. {
  303. sudo apt update && sudo apt full-upgrade -V
  304. }
  305. function gct()
  306. {
  307. token=$(pass gist/github)
  308. curl -u Awan:$token -X POST https://api.github.com/user/repos -d '{"name":"'$1'"}'
  309. git init
  310. git remote add origin git@github.com:Awan/$1.git
  311. }
  312. endot ()
  313. {
  314. cd ~/cfg
  315. tar czf encrypted.tar.gz etc/.local/share/misc misc
  316. gpg -er 5CBC7BC7 encrypted.tar.gz
  317. rm encrypted.tar.gz
  318. }
  319. dedot ()
  320. {
  321. cd ~/cfg
  322. gpg -do encrypted.tar.gz encrypted.tar.gz.gpg
  323. tar xvf encrypted.tar.gz
  324. rm encrypted.tar.gz
  325. stow etc
  326. }
  327. sne ()
  328. {
  329. sudo systemctl --now enable $1
  330. }
  331. snd ()
  332. {
  333. sudo systemctl stop $1
  334. }
  335. gadd ()
  336. {
  337. sudo gpasswd -a "$USER" "$1"
  338. }
  339. ed ()
  340. {
  341. "$EDITOR" "$@"
  342. }
  343. mpgo ()
  344. {
  345. mkdir /tmp/mpv -p
  346. if [[ -n $1 ]]; then
  347. clipboard=$1
  348. else
  349. clipboard=$(xsel -b)
  350. fi
  351. if [[ $clipboard =~ ^http ]] || [[ -f $clipboard ]]; then
  352. echo "$clipboard" > /tmp/mpv/last_link
  353. # ytdl messes up direct links for some reason (slow)
  354. mpv --no-ytdl --screenshot-template="./%tY.%tm.%td_%tH:%tM:%tS" "$clipboard"
  355. elif [[ $clipboard =~ ^magnet ]]; then
  356. echo "$clipboard" > /tmp/mpv/last_link
  357. peerflix "$clipboard" --mpv -- --no-ytdl \
  358. --screenshot-template="./%tY.%tm.%td_%tH:%tM:%tS"
  359. fi
  360. }
  361. mplast ()
  362. {
  363. mpgo "$(< /tmp/mpv/last_link)"
  364. }
  365. arec ()
  366. {
  367. if [[ $# -ne 1 ]]; then
  368. return 1
  369. fi
  370. arecord -vv -f wav "$1"
  371. }
  372. ram ()
  373. {
  374. local sum
  375. local items
  376. local app="$1"
  377. if [ -z "$app" ]; then
  378. echo "First argument - pattern to grep from processes"
  379. else
  380. sum=0
  381. for i in `ps aux | grep -i "$app" | grep -v "grep" | awk '{print $6}'`; do
  382. sum=$(($i + $sum))
  383. done
  384. sum=$(echo "scale=2; $sum / 1024.0" | bc)
  385. if [[ $sum != "0" ]]; then
  386. echo "${fg[blue]}${app}${reset_color} uses ${fg[green]}${sum}${reset_color} MBs of RAM."
  387. else
  388. echo "There are no processes with pattern '${fg[blue]}${app}${reset_color}' are running."
  389. fi
  390. fi
  391. }
  392. pdfmerge ()
  393. {
  394. local tomerge
  395. tomerge=""
  396. for file in "$@"; do
  397. tomerge="$tomerge $file"
  398. done
  399. pdftk "$tomerge" cat output mergd.pdf
  400. }
  401. bkmeup ()
  402. {
  403. cp -riv $1 ${1}-$(date +%d-%m-%Y-%H:%M).bak
  404. }
  405. sprunge ()
  406. {
  407. tail -n +1 -- "$@" | curl -F 'sprunge=<-' http://sprunge.us
  408. }
  409. removeaudio ()
  410. {
  411. ffmpeg -i $1 -vcodec copy -an $2
  412. }
  413. apkname ()
  414. {
  415. package="$1"
  416. adb shell pm list packages | awk -F: -v pkg=$package 'index($0, pkg) {print $2}'
  417. }
  418. apkpath ()
  419. {
  420. package="$1"
  421. adb shell pm path $package | awk -F: -v pkg=$package 'index($0, pkg) {print $2}'
  422. }
  423. playandroid ()
  424. # play music files on android. first argument should be the path and second
  425. # should be the file format, like, audio/mp3, video/mp4
  426. {
  427. music_file="$1"
  428. format="$2"
  429. adb shell am start -a android.intent.action.VIEW -d file://$music_file -t $format
  430. }
  431. apkrun ()
  432. # starts an apk which you give to it as first argument. You can get the name of
  433. # the package by using `adb shell pm list packages`
  434. {
  435. package_name="$1"
  436. adb shell monkey -p $package_name 1
  437. }
  438. apkstop ()
  439. {
  440. package_name="$1"
  441. adb shell am force-stop $package_name
  442. }
  443. apkun ()
  444. {
  445. adb shell pm uninstall "$1"
  446. }
  447. lightmin ()
  448. # Set brightness to minimum
  449. {
  450. echo 100 | sudo tee /sys/class/backlight/intel_backlight/brightness
  451. }
  452. lightmax ()
  453. # Set brightness to maximum
  454. {
  455. echo 852 | sudo tee /sys/class/backlight/intel_backlight/brightness
  456. }
  457. #light ()
  458. # Set brightness as first argument
  459. #{
  460. # new_brightness="$1"
  461. # echo $new_brightness | sudo tee
  462. # /sys/class/backlight/intel_backlight/#brightness
  463. #}
  464. bulkrename ()
  465. # replace spaces with underscores, change upper to lower case, remove extra # underscores.
  466. {
  467. find "$1" -depth | while read line; do
  468. dir="$(dirname "$line")"
  469. old="$(basename "$line")"
  470. new="$(echo $old | tr ' ' '_' \
  471. | tr -d '()[]{},?!' | tr -d "'" \
  472. | tr '[[:upper:]]' '[[:lower:]]' \
  473. | sed 's/__/_/g' | sed 's/_-_/-/g' )"
  474. [[ "$old" != "$new" ]] && mv -iv "$dir/$old" "$dir/$new"
  475. done
  476. }
  477. tf ()
  478. {
  479. string="$1"
  480. toilet -f smmono12.tlf $string | lolcat
  481. }
  482. aur ()
  483. {
  484. cd $HOME/git
  485. package_name="$1"
  486. aur_url="https://aur.archlinux.org"
  487. git clone $aur_url/$package_name
  488. cd $package_name
  489. vim PKGBUILD
  490. }
  491. #haq ()
  492. ## Listen to Holy Quran's Ayah by numbers.
  493. #{
  494. #zero_pad(){
  495. # # zero_pad <string> <length>
  496. # [ ${#1} -lt $2 ] && printf "%0$(($2-${#1}))d" ''
  497. # printf "%s\n" "$1"
  498. #}
  499. #which_surah="$1"
  500. #which_ayah="$2"
  501. #qari="$3"
  502. #shuraim_dir=$HOME/kit/verses/shuraim
  503. #sudais_dir=$HOME/kit/verses/sudais
  504. #surah=$(zero_pad $which_surah 3)
  505. #ayah=$(zero_pad $which_ayah 3)
  506. #
  507. #play_shuraim(){
  508. # /usr/bin/mplayer $shuraim_dir/$surah$ayah.mp3
  509. #}
  510. #play_sudais(){
  511. # /usr/bin/mplayer $sudais_dir/$surah$ayah.mp3
  512. #}
  513. #if [[ $qari == 'shuraim' ]]; then
  514. # play_shuraim
  515. #fi
  516. #
  517. #if [[ $qari == 'sudais' ]]; then
  518. # play_sudais
  519. #fi
  520. #}
  521. gfc ()
  522. # git initial commit
  523. {
  524. arabic="بِسْمِ ٱللّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيم"
  525. english='In the name of Allah SWT, the most Gracious, the most Merciful.'
  526. git commit -m "$arabic - $english"
  527. }
  528. ports ()
  529. {
  530. sudo lsof -nPi | grep -i listen | awk '{print substr($1, 1, 7), substr($3, 1, 7), $5, $8, $9}' | sort | uniq | tr ' ' '\t'
  531. }
  532. listcon ()
  533. {
  534. port=$1
  535. host=$(uname)
  536. netstat -atn | grep "$port" | sort -k5
  537. }
  538. r ()
  539. {
  540. if [[ "$TERM" == rxvt-unicode-256color ]]; then
  541. ranger
  542. else
  543. urxvtc -e ranger 2>/dev/null || urxvt -e ranger &
  544. fi
  545. }
  546. replace_all() { ag "$1" -l | xargs sed -i -e "s/$1/$2/g" }
  547. aw ()
  548. # search arch wiki
  549. {
  550. query="$1"
  551. site="https://wiki.archlinux.org/index.php?search="
  552. $BROWSER $site$query
  553. }
  554. purgegit () {
  555. # Create a temporary branch and checkout
  556. git checkout --orphan purge
  557. # Add all the files and commit
  558. git commit -am 'In the name of Allah, the most Gracious, the most Merciful'
  559. # Delete the master branch
  560. git branch -D master
  561. # Rename the temporary branch to master
  562. git branch -m master
  563. # Push the changes forcefully
  564. git push -uf origin master
  565. }
  566. wallpaper ()
  567. {
  568. # Convert an image into wallpaper using imagemagick
  569. # and then sets it as wallpapers using feh
  570. convert "${1}" -gravity Center -resize 1920 -crop 1920x1080+0+0 png:- \
  571. | feh --bg-scale -
  572. }
  573. function gr()
  574. {
  575. # Search recursively with grep
  576. grep --color=auto -R "$*"
  577. }
  578. function calc()
  579. # Start a calculator
  580. {
  581. python -q
  582. }
  583. transfer() {
  584. tmp_file=$(mktemp /tmp/transfer_XXXXXXXX)
  585. trap 'rm ${tmp_file}' EXIT
  586. # Help. In case no arguments specified
  587. if [[ $# == 0 ]]; then
  588. echo "No arguments specified. Usage:"
  589. echo "$ transfer /tmp/test.md"
  590. echo "$ cat /tmp/test.md | transfer test.md"
  591. exit 1
  592. fi
  593. # Upload either from file or stdin
  594. if tty -s; then
  595. basefile=$(basename "${1}" | sed -e 's/[^a-zA-Z0-9._-]/-/g')
  596. curl --progress-bar --upload-file "${1}" "https://transfer.sh/${basefile}" >> "${tmp_file}"
  597. else
  598. curl --progress-bar --upload-file "-" "https://transfer.sh/${1}" >> "${tmp_file}"
  599. fi
  600. # Print download link
  601. cat "${tmp_file}"
  602. echo
  603. }
  604. function push() {
  605. # http post files
  606. file_to_be_pushed="$1"
  607. type_of_file="$2"
  608. if [[ $type_of_file = 'f' || -z $type_of_file ]]; then
  609. curl -F "file=@$file_to_be_pushed" http://0x0.st | xclip
  610. elif [[ $type_of_file = 'u' ]]; then
  611. curl -F "url=$file_to_be_pushed" http://0x0.st | xclip
  612. elif [[ $type_of_file = 's' ]]; then
  613. curl -F "shorten=$file_to_be_pushed" http://0x0.st | xclip
  614. fi
  615. }
  616. m() {
  617. mpd_state="$(mpc | awk '/playing|paused/ {print $1}')"
  618. files=$@
  619. if [ $mpd_state = '[playing]' ]; then
  620. state=0
  621. else
  622. state=1
  623. fi
  624. play() {
  625. if [ $state = 0 ]; then
  626. mpc pause >/dev/null
  627. /usr/bin/mpv $files
  628. mpc play >/dev/null
  629. else
  630. /usr/bin/mpv $files
  631. fi
  632. }
  633. play
  634. }
  635. dua() {
  636. echo "بارك الله فيك وبارك لك ونفع بك حقق الله أمنياتك وأسعدك في الدنيا والآخرة" \
  637. | xclip -selection clipboard
  638. }
  639. sitemap() {
  640. # submit sitemap to google
  641. google_url="https://www.google.com/webmasters/sitemaps/ping?sitemap="
  642. path=$1
  643. /usr/bin/curl $google_url$path
  644. }
  645. baqara() {
  646. /usr/bin/mpv --no-resume-playback ~/haq/shuraim/002{001..286}.mp3
  647. }
  648. gifspeed() {
  649. # reduce gif speed to half
  650. mkdir -p gifs_with_speed
  651. for file in *.gif
  652. do
  653. convert -delay 10x100 $file gifs_with_speed/`basename $file`
  654. done
  655. }
  656. mkuser () {
  657. # Create a new user with creating new homedir, zsh as shell, adding it to
  658. # audio, video and wheel group
  659. username="$1"
  660. sudo useradd -m -G wheel,input,audio,video -s `which zsh` "$username" && sudo passwd "$username"
  661. }
  662. Q () {
  663. # listen to Holy Quran
  664. Surah="$1"
  665. Ayah="$2"
  666. path="$HOME/haq/shuraim/"
  667. if [ -z "$Surah" ] || [ -z "$Ayah" ]; then
  668. exit 1
  669. fi
  670. printf -v file '%03d%03d.mp3' "$Surah" "$Ayah" && \
  671. /usr/bin/mpv --no-resume-playback "$path""$file"
  672. }
  673. dep () {
  674. # deploy changes to website after you have pushed the master repo with same
  675. # commit message
  676. msg="$(git log -n1 --format='%B')"
  677. hugo
  678. cd public
  679. git add -A
  680. git commit -m "$msg"
  681. git push
  682. }