functions 24 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096
  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. mkd ()
  12. {
  13. mkdir -p "$@" && cd "$_";
  14. }
  15. # for webm videos to mp4
  16. webm2mp4 ()
  17. {
  18. for file in *.webm
  19. do
  20. ffmpeg -i "$file" "`basename "$file" .webm`.mp4"
  21. done
  22. }
  23. # mp4 to mp3
  24. mp42mp3 ()
  25. {
  26. CURRENTMP4HERE=$(ls *.mp4 | wc -l)
  27. notify-send "Found $CURRENTMP4HERE mp4s, gonna convert them now, be patient"
  28. for file in *.mp4
  29. do
  30. ffmpeg -y -i "$file" "`basename "$file" .mp4`.mp3"
  31. done
  32. notify-send "All $CURRENTMP4HERE mp4s have been converted to mp3s and now we are moving them to your music dir"
  33. CURRENTMP3INMPD=$(ls $HOME/mus/*.mp3 | wc -l)
  34. notify-send "You have $CURRENTMP3INMPD mp3s in your database"
  35. mv *.mp3 ~/mus/ -v
  36. notify-send "All mp3s have been moved to music dir."
  37. TOTAL=$(($CURRENTMP3INMPD + $CURRENTMP4HERE))
  38. notify-send "You have got $CURRENTMP4HERE new mp3s. Now you have $TOTAL songs in database. Enjoy your music"
  39. }
  40. # mp3 to aac
  41. mp3toaac () {
  42. for file in *.mp3
  43. do
  44. ffmpeg -y -i "$file" "`basename "$file" .mp3`.aac"
  45. done
  46. }
  47. speedup ()
  48. {
  49. base=$(basename $1)
  50. ext="${base##*.}"
  51. base="${base%.*}"
  52. ffmpeg -i $1 -filter:v "setpts=0.5*PTS" $base'_speed.'$ext
  53. notify-send "your video has got speed. Enjoy"
  54. }
  55. # aac + image = mp4
  56. aactomkv ()
  57. {
  58. for files in *.aac
  59. do
  60. 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"
  61. done
  62. }
  63. hdimg () {
  64. # converts images into HD wallpapers 1920x1080
  65. # Accepts globbing as first argument e.g. jpg as first argument will convert all
  66. # jpgs into HD images and saves them into new dir resized in same directory
  67. ext="$1"
  68. mkdir resized 2>/dev/null
  69. for file in *."$ext"
  70. do
  71. convert $file -resize 1920x1080! resized/`basename $file .$ext`.$ext
  72. done
  73. }
  74. mp3tomp4 ()
  75. # 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`
  76. # if not a multiple of 2, `convert image.jpg -resize 1024x512! imag2.jpg`
  77. # Usage:
  78. # mp3tomp4 image.jpg audio.mp3 output.mp4
  79. {
  80. ffmpeg -loop 1 -r 1 -i $1 -i $2 -vcodec libx264 -acodec copy -shortest $3
  81. }
  82. pl ()
  83. {
  84. mpc searchplay $1
  85. }
  86. mergeaudio ()
  87. # Create a .txt file in same directory and add files to be merged there as "file file1 and on new line, file file2"
  88. # Usage:
  89. # mergeaudio files.txt output.mp3
  90. {
  91. ffmpeg -f concat -safe 0 -i $1 -c copy $2
  92. }
  93. mergeaudiotovideo ()
  94. # maps audio with video, first arg should be video, second should be audio and
  95. # third should be the output
  96. {
  97. ffmpeg -i $1 -i $2 -c copy -map 0:v:0 -map 1:a:0 $3
  98. }
  99. # Jobs mail
  100. apply ()
  101. {
  102. gpg -dq $HOME/bin/misc/job.gpg | mutt -s "Applying for Job" $1
  103. }
  104. # Encrypt a file to myself
  105. ei ()
  106. {
  107. gpg -er 5CBC7BC7 $1
  108. }
  109. # Decrypt a file
  110. di ()
  111. {
  112. gpg -do $1 $2
  113. }
  114. # Bakchod
  115. bakchod ()
  116. {
  117. echo "$@" | tr a-zA-Z n-za-mN-ZA-M
  118. }
  119. # mailto
  120. mailto ()
  121. {
  122. $TERMINAL -e mutt "$@"
  123. }
  124. aa_256 ()
  125. {
  126. local o= i= x=`tput op` cols=`tput cols` y= oo= yy=;
  127. y=`printf %$(($cols-6))s`;
  128. yy=${y// /=};
  129. for i in {0..256};
  130. do
  131. o=00${i};
  132. oo=`echo -en "setaf ${i}\nsetab ${i}\n"|tput -S`;
  133. echo -e "${o:${#o}-3:3} ${oo}${yy}${x}";
  134. done
  135. }
  136. ht() {
  137. a=$(cat); curl -X POST -s -d "$a" https://hastebin.com/documents | awk -F '"' '{print "https://hastebin.com/"$4}' | xclip ;
  138. }
  139. fs()
  140. {
  141. if du -b /dev/null > /dev/null 2>&1; then
  142. local arg=-sbh;
  143. else
  144. local arg=-sh;
  145. fi
  146. if [[ -n "$@" ]]; then
  147. du $arg -- "$@";
  148. else
  149. du $arg .[^.]* ./*;
  150. fi;
  151. }
  152. dataurl()
  153. {
  154. local mimeType=$(file -b --mime-type "$1");
  155. if [[ $mimeType == text/* ]]; then
  156. mimeType="${mimeType};charset=utf-8";
  157. fi
  158. echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')";
  159. }
  160. escape()
  161. {
  162. printf "\\\x%s" $(printf "$@" | xxd -p -c1 -u);
  163. # print a newline unless we’re piping the output to another program
  164. if [ -t 1 ]; then
  165. echo ""; # newline
  166. fi;
  167. }
  168. # v()
  169. # {
  170. # if [ $# -eq 0 ]; then
  171. # $EDITOR .;
  172. # else
  173. # $EDITOR "$@";
  174. # fi;
  175. # }
  176. #
  177. o()
  178. {
  179. if [ $# -eq 0 ]; then
  180. ranger .;
  181. else
  182. ranger "$@";
  183. fi;
  184. }
  185. tre()
  186. {
  187. tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX;
  188. }
  189. ix() {
  190. local opts
  191. local OPTIND
  192. [ -f "$HOME/.netrc" ] && opts='-n'
  193. while getopts ":hd:i:n:" x; do
  194. case $x in
  195. h) echo "ix [-d ID] [-i ID] [-n N] [opts]"; return;;
  196. d) $echo curl $opts -X DELETE ix.io/$OPTARG; return;;
  197. i) opts="$opts -X PUT"; local id="$OPTARG";;
  198. n) opts="$opts -F read:1=$OPTARG";;
  199. esac
  200. done
  201. shift $(($OPTIND - 1))
  202. [ -t 0 ] && {
  203. local filename="$1"
  204. shift
  205. [ "$filename" ] && {
  206. curl $opts -F f:1=@"$filename" $* ix.io/$id
  207. return
  208. }
  209. echo "^C to cancel, ^D to send."
  210. }
  211. curl $opts -F f:1='<-' $* ix.io/$id
  212. }
  213. shebang() {
  214. if i=$(which $1);
  215. then
  216. printf '#!/usr/bin/env %s\n\n' $1 > $2 && chmod 755 $2 && $EDITOR + $2 && chmod 755 $2;
  217. else
  218. echo "'which' could not find $1, is it in your \$PATH?";
  219. fi;
  220. # in case the new script is in path, this throw out the command hash table and
  221. # start over (man zshbuiltins)
  222. rehash
  223. }
  224. webcam () {
  225. mplayer -cache 128 -tv driver=v4l2:width=350:height=350 -vo xv tv:// -noborder -geometry "+1340+445" -ontop -quiet 2>/dev/null >/dev/null
  226. }
  227. psg () {
  228. pass generate "$1" --clip
  229. cd ~/.password-store
  230. git push
  231. cd -
  232. }
  233. weather() {
  234. curl wttr.in/"$1"
  235. }
  236. cnsp () {
  237. sudo /etc/rc.d/crond stop
  238. sleep 1
  239. sudo /etc/rc.d/crond status
  240. }
  241. cnst () {
  242. sudo /etc/rc.d/crond start
  243. sleep 1
  244. sudo /etc/rc.d/crond status
  245. }
  246. ko () {
  247. a=$(cat)
  248. curl -X POST -s -d "raw:$a" http://kopy.io/documents | awk -F '"' '{print "http://kopy.io/"$4}'
  249. }
  250. pb()
  251. {
  252. local url='https://paste.c-net.org/'
  253. if (( $# )); then
  254. local file
  255. for file; do
  256. curl -s \
  257. --data-binary @"$file" \
  258. --header "X-FileName: ${file##*/}" \
  259. "$url"
  260. done
  261. else
  262. curl -s --data-binary @- "$url"
  263. fi
  264. }
  265. pg()
  266. {
  267. local url='https://paste.c-net.org/'
  268. if (( $# )); then
  269. local arg
  270. for arg; do
  271. curl -s "${url}${arg##*/}"
  272. done
  273. else
  274. local arg
  275. while read -r arg; do
  276. curl -s "${url}${arg##*/}"
  277. done
  278. fi
  279. }
  280. ap()
  281. {
  282. sudo apt update && sudo apt full-upgrade -V
  283. }
  284. gct()
  285. {
  286. token=$(pass gist/github)
  287. curl -u Awan:$token -X POST https://api.github.com/user/repos -d '{"name":"'$1'"}'
  288. git init
  289. git remote add origin git@github.com:Awan/$1.git
  290. }
  291. endot ()
  292. {
  293. cd ~/cfg
  294. [[ -f ~/cfg/encrypted.tar.gz.age ]] && rm ~/cfg/encrypted.tar.gz.age
  295. tar cz etc/.local/share/misc misc | age -R ~/.ssh/id_ed25519.pub > encrypted.tar.gz.age
  296. }
  297. dedot ()
  298. {
  299. cd ~/cfg
  300. age -i ~/.ssh/id_ed25519 -d -o encrypted.tar.gz encrypted.tar.gz.age
  301. tar xf encrypted.tar.gz
  302. rm encrypted.tar.gz
  303. stow etc
  304. }
  305. sne ()
  306. {
  307. sudo systemctl --now enable $1
  308. }
  309. snd ()
  310. {
  311. sudo systemctl stop $1
  312. }
  313. gadd ()
  314. {
  315. sudo gpasswd -a "$USER" "$1"
  316. }
  317. ed ()
  318. {
  319. "$EDITOR" "$@"
  320. }
  321. mpgo ()
  322. {
  323. mkdir /tmp/mpv -p
  324. if [[ -n $1 ]]; then
  325. clipboard=$1
  326. else
  327. clipboard=$(xsel -b)
  328. fi
  329. if [[ $clipboard =~ ^http ]] || [[ -f $clipboard ]]; then
  330. echo "$clipboard" > /tmp/mpv/last_link
  331. # ytdl messes up direct links for some reason (slow)
  332. mpv --no-ytdl --screenshot-template="./%tY.%tm.%td_%tH:%tM:%tS" "$clipboard"
  333. elif [[ $clipboard =~ ^magnet ]]; then
  334. echo "$clipboard" > /tmp/mpv/last_link
  335. peerflix "$clipboard" --mpv -- --no-ytdl \
  336. --screenshot-template="./%tY.%tm.%td_%tH:%tM:%tS"
  337. fi
  338. }
  339. mplast ()
  340. {
  341. mpgo "$(< /tmp/mpv/last_link)"
  342. }
  343. arec ()
  344. {
  345. if [[ $# -ne 1 ]]; then
  346. return 1
  347. fi
  348. arecord -vv -f wav "$1"
  349. }
  350. ram ()
  351. {
  352. local sum
  353. local items
  354. local app="$1"
  355. if [ -z "$app" ]; then
  356. echo "First argument - pattern to grep from processes"
  357. else
  358. sum=0
  359. for i in `ps aux | grep -i "$app" | grep -v "grep" | awk '{print $6}'`; do
  360. sum=$(($i + $sum))
  361. done
  362. sum=$(echo "scale=2; $sum / 1024.0" | bc)
  363. if [[ $sum != "0" ]]; then
  364. echo "${fg[blue]}${app}${reset_color} uses ${fg[green]}${sum}${reset_color} MBs of RAM."
  365. else
  366. echo "There are no processes with pattern '${fg[blue]}${app}${reset_color}' are running."
  367. fi
  368. fi
  369. }
  370. pdfmerge ()
  371. {
  372. local tomerge
  373. tomerge=""
  374. for file in "$@"; do
  375. tomerge="$tomerge $file"
  376. done
  377. pdftk "$tomerge" cat output mergd.pdf
  378. }
  379. bkmeup ()
  380. {
  381. cp -riv $1 ${1}-$(date +%d-%m-%Y-%H:%M).bak
  382. }
  383. sprunge ()
  384. {
  385. tail -n +1 -- "$@" | curl -F 'sprunge=<-' http://sprunge.us
  386. }
  387. removeaudio ()
  388. {
  389. ffmpeg -i $1 -vcodec copy -an $2
  390. }
  391. apkname ()
  392. {
  393. package="$1"
  394. adb shell pm list packages | awk -F: -v pkg=$package 'index($0, pkg) {print $2}'
  395. }
  396. apkpath ()
  397. {
  398. package="$1"
  399. adb shell pm path $package | awk -F: -v pkg=$package 'index($0, pkg) {print $2}'
  400. }
  401. apkbkup ()
  402. {
  403. # Create a backup for an android application
  404. # Get application name using apkname function
  405. # This backup can be restored later using `adb install application.apk; adb restore backup.adb`
  406. backup_file="$1".adb
  407. application="$2"
  408. adb backup -f "$backup_file" -apk "$application"
  409. }
  410. playandroid ()
  411. # play music files on android. first argument should be the path and second should be the file format, like, audio/mp3, video/mp4
  412. {
  413. music_file="$1"
  414. format="$2"
  415. adb shell am start -a android.intent.action.VIEW -d file://$music_file -t $format
  416. }
  417. imei ()
  418. # Get IMEI from connected android devices
  419. {
  420. adb shell 'service call iphonesubinfo 1 | grep -o "[0-9a-f]\{8\} " | tail -n+3 | while read a; do echo -n "\u${a:4:4}\u${a:0:4}"; done'
  421. }
  422. apkrun ()
  423. # starts an apk which you give to it as first argument. You can get the name of
  424. # the package by using `adb shell pm list packages`
  425. {
  426. package_name="$1"
  427. adb shell monkey -p $package_name 1
  428. }
  429. apkstop ()
  430. {
  431. package_name="$1"
  432. adb shell am force-stop $package_name
  433. }
  434. apkun ()
  435. {
  436. adb shell pm uninstall "$1"
  437. }
  438. lightmin ()
  439. # Set brightness to minimum
  440. {
  441. echo 100 | sudo tee /sys/class/backlight/intel_backlight/brightness
  442. }
  443. lightmax ()
  444. # Set brightness to maximum
  445. {
  446. echo 852 | sudo tee /sys/class/backlight/intel_backlight/brightness
  447. }
  448. #light ()
  449. # Set brightness as first argument
  450. #{
  451. # new_brightness="$1"
  452. # echo $new_brightness | sudo tee
  453. # /sys/class/backlight/intel_backlight/#brightness
  454. #}
  455. bulkrename ()
  456. # replace spaces with underscores, change upper to lower case, remove extra # underscores.
  457. {
  458. find "$1" -depth | while read line; do
  459. dir="$(dirname "$line")"
  460. old="$(basename "$line")"
  461. new="$(echo $old | tr ' ' '_' \
  462. | tr -d '()[]{},?!' | tr -d "'" \
  463. | tr '[[:upper:]]' '[[:lower:]]' \
  464. | sed 's/__/_/g' | sed 's/_-_/-/g' )"
  465. [[ "$old" != "$new" ]] && mv -iv "$dir/$old" "$dir/$new"
  466. done
  467. }
  468. tf ()
  469. {
  470. string="$1"
  471. toilet -f smmono12.tlf $string | lolcat
  472. }
  473. aur ()
  474. {
  475. cd $HOME/git
  476. package_name="$1"
  477. aur_url="https://aur.archlinux.org"
  478. git clone $aur_url/$package_name
  479. cd $package_name
  480. $EDITOR PKGBUILD
  481. }
  482. #haq ()
  483. ## Listen to Holy Quran's Ayah by numbers.
  484. #{
  485. #zero_pad(){
  486. # # zero_pad <string> <length>
  487. # [ ${#1} -lt $2 ] && printf "%0$(($2-${#1}))d" ''
  488. # printf "%s\n" "$1"
  489. #}
  490. #which_surah="$1"
  491. #which_ayah="$2"
  492. #qari="$3"
  493. #shuraim_dir=$HOME/kit/verses/shuraim
  494. #sudais_dir=$HOME/kit/verses/sudais
  495. #surah=$(zero_pad $which_surah 3)
  496. #ayah=$(zero_pad $which_ayah 3)
  497. #
  498. #play_shuraim(){
  499. # /usr/bin/mplayer $shuraim_dir/$surah$ayah.mp3
  500. #}
  501. #play_sudais(){
  502. # /usr/bin/mplayer $sudais_dir/$surah$ayah.mp3
  503. #}
  504. #if [[ $qari == 'shuraim' ]]; then
  505. # play_shuraim
  506. #fi
  507. #
  508. #if [[ $qari == 'sudais' ]]; then
  509. # play_sudais
  510. #fi
  511. #}
  512. gfc ()
  513. # git initial commit
  514. {
  515. arabic="بِسْمِ ٱللّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيم"
  516. english='In the name of Allah SWT, the most Gracious, the most Merciful.'
  517. git commit -m "$arabic - $english"
  518. }
  519. ports ()
  520. {
  521. sudo lsof -nPi | grep -i listen | awk '{print substr($1, 1, 7), substr($3, 1, 7), $5, $8, $9}' | sort | uniq | tr ' ' '\t'
  522. }
  523. listcon ()
  524. {
  525. port=$1
  526. host=$(uname)
  527. netstat -atn | grep "$port" | sort -k5
  528. }
  529. replace_all() { ag "$1" -l | xargs sed -i -e "s/$1/$2/g" }
  530. aw ()
  531. # search arch wiki
  532. {
  533. query="$1"
  534. site="https://wiki.archlinux.org/index.php?search="
  535. $BROWSER $site$query
  536. }
  537. purgegit () {
  538. # Create a temporary branch and checkout
  539. git checkout --orphan purge
  540. # Add all the files and commit
  541. git commit -am 'In the name of Allah, the most Gracious, the most Merciful'
  542. # Delete the master branch
  543. git branch -D master
  544. # Rename the temporary branch to master
  545. git branch -m master
  546. # Push the changes forcefully
  547. git push -uf origin master
  548. }
  549. wallpaper ()
  550. {
  551. # Convert an image into wallpaper using imagemagick
  552. # and then sets it as wallpapers using feh
  553. convert "${1}" -gravity Center -resize 1920 -crop 1920x1080+0+0 png:- \
  554. | feh --bg-scale -
  555. }
  556. gr()
  557. {
  558. # Search recursively with grep
  559. grep --color=auto -R "$*"
  560. }
  561. calc()
  562. # Start a calculator
  563. {
  564. python -q
  565. }
  566. transfer() {
  567. tmp_file=$(mktemp /tmp/transfer_XXXXXXXX)
  568. trap 'rm ${tmp_file}' EXIT
  569. # Help. In case no arguments specified
  570. if [[ $# == 0 ]]; then
  571. echo "No arguments specified. Usage:"
  572. echo "$ transfer /tmp/test.md"
  573. echo "$ cat /tmp/test.md | transfer test.md"
  574. exit 1
  575. fi
  576. # Upload either from file or stdin
  577. if tty -s; then
  578. basefile=$(basename "${1}" | sed -e 's/[^a-zA-Z0-9._-]/-/g')
  579. curl --progress-bar --upload-file "${1}" "https://transfer.sh/${basefile}" >> "${tmp_file}"
  580. else
  581. curl --progress-bar --upload-file "-" "https://transfer.sh/${1}" >> "${tmp_file}"
  582. fi
  583. # Print download link
  584. cat "${tmp_file}"
  585. echo
  586. }
  587. push() {
  588. # http post files
  589. file_to_be_pushed="$1"
  590. type_of_file="$2"
  591. if [ "$type_of_file" = "f" ] || [ -z "$type_of_file" ]; then
  592. curl -F "file=@$file_to_be_pushed" http://0x0.st | xclip
  593. elif [ "$type_of_file" = "u" ]; then
  594. curl -F "url=$file_to_be_pushed" http://0x0.st | xclip
  595. elif [ "$type_of_file" = "s" ]; then
  596. curl -F "shorten=$file_to_be_pushed" http://0x0.st | xclip
  597. fi
  598. }
  599. #m() {
  600. #
  601. # mpd_state="$(mpc | awk '/playing|paused/ {print $1}')"
  602. # files=$@
  603. # if [ $mpd_state = '[playing]' ]; then
  604. # state=0
  605. # else
  606. # state=1
  607. # fi
  608. #
  609. # play() {
  610. # if [ $state = 0 ]; then
  611. # mpc pause >/dev/null
  612. # /usr/bin/mpv $files
  613. # mpc play >/dev/null
  614. # else
  615. # /usr/bin/mpv $files
  616. # fi
  617. # }
  618. #play
  619. #}
  620. dua() {
  621. echo "بارك الله فيك وبارك لك ونفع بك حقق الله أمنياتك وأسعدك في الدنيا والآخرة" \
  622. | xclip -selection clipboard
  623. }
  624. sitemap() {
  625. # submit sitemap to google
  626. # For simplicity, add sitemap to robots.txt and then use this function to
  627. # update it in Google like this: sitemap https://abdullah.today/robots.txt
  628. google_url="https://www.google.com/webmasters/sitemaps/ping?sitemap="
  629. path=$1
  630. /usr/bin/curl $google_url$path
  631. }
  632. baqara() {
  633. /usr/bin/mpv --no-resume-playback ~/haq/shuraim/002{001..286}.mp3
  634. }
  635. gifspeed() {
  636. # reduce gif speed to half
  637. mkdir -p gifs_with_speed
  638. for file in *.gif
  639. do
  640. convert -delay 10x100 $file gifs_with_speed/`basename $file`
  641. done
  642. }
  643. mkuser () {
  644. # Create a new user with creating new homedir, zsh as shell, adding it to
  645. # audio, video and wheel group
  646. username="$1"
  647. sudo useradd -m -G wheel,input,audio,video -s `which zsh` "$username" && sudo passwd "$username"
  648. }
  649. Q () {
  650. # listen to Holy Quran
  651. Surah="$1"
  652. Ayah="$2"
  653. Qari="$3"
  654. path="$HOME/haq/sudais/"
  655. [ -z "$Qari" ] && path="$HOME/haq/shuraim/"
  656. if [ -z "$Surah" ] || [ -z "$Ayah" ]; then
  657. exit 1
  658. fi
  659. printf -v file '%03d%03d.mp3' "$Surah" "$Ayah" && \
  660. /usr/bin/mpv --no-resume-playback "$path""$file"
  661. }
  662. Qt () {
  663. # listen Holy Quran with Urdu translation
  664. # Surah is a multipurpose Python script which feeds metadata into Verses.
  665. _listen="$(Surah $1)"
  666. surah=$(echo -n "${_listen//[[:space:]]/}.mp3")
  667. Quran_path="$HOME/kit/mp3/urdu/"
  668. /usr/bin/mpv --no-resume-playback $Quran_path$surah &
  669. }
  670. mg () {
  671. awk -v newsums="$(makepkg -g)" '
  672. BEGIN {
  673. if (!newsums) exit 1
  674. }
  675. /^[[:blank:]]*(md|sha)[[:digit:]]+sums=/,/\)[[:blank:]]*$/ {
  676. if (!i) print newsums; i++
  677. next
  678. }
  679. 1
  680. ' PKGBUILD > PKGBUILD.new && mv PKGBUILD{.new,}
  681. }
  682. pacaur() {
  683. comm -23 <(pacman -Qqm | sort) <(curl https://aur.archlinux.org/packages.gz | gzip -cd | sort)
  684. }
  685. vers() {
  686. output_file="$1"
  687. surah="$2"
  688. verses="$3"
  689. if [ -z "$surah" ] || [ -z "$verses" ]; then
  690. exit 1
  691. fi
  692. for i in $(seq 1 $verses);
  693. do
  694. printf -v file '%03d%03d.mp3' $surah $i; echo "## _Ayat $i :arrow_heading_down:_\n{{< audio mp3=https://gitlab.com/Abdullah/haq/-/raw/master/shuraim/$file >}}\n" >> $output_file;
  695. done
  696. }
  697. getscr() {
  698. # Sometimes needed to cp scrot to ~/pix/scrots
  699. scrot_file="/tmp/foo.png"
  700. scrot_dir="$HOME/pix/scrots/"
  701. new_scrot_file="$1"
  702. [ -z $new_scrot_file ] && new_scrot_file="scrot-$(date +%d-%m-%Y-%H-%M-%S)"
  703. cp $scrot_file $scrot_dir$new_scrot_file.png && \
  704. echo $scrot_dir$new_scrot_file.png && \
  705. notify-send -t 3500 -i \
  706. $HOME/.local/share/icons/drops/imgur.png \
  707. "Screenshot saved: $new_scrot_file.png"
  708. feh $scrot_dir$new_scrot_file.png
  709. }
  710. srm () {
  711. # Shred and rm
  712. files_to_be_operated_on="$@"
  713. shred "$files_to_be_operated_on" && rm "$files_to_be_operated_on"
  714. }
  715. hg () {
  716. # runs hugo in root dir of my website project
  717. webdir="$HOME/git/mysite/"
  718. echo "Current dir is $PWD"
  719. echo "Building your website in $webdir"
  720. cd "$webdir"
  721. hugo --gc=true
  722. cd public && echo "add your files and commit them!"
  723. }
  724. dep ()
  725. {
  726. # deploy changes to website after you have pushed the master repo with same
  727. # commit message
  728. # fetch latest commit message
  729. site_url="https://abdullah.today"
  730. source_dir="$HOME/git/mysite/"
  731. rendered_dir="$HOME/git/mysite/public/"
  732. cd "$source_dir"
  733. msg="$(git log -n1 --format='%B')"
  734. hugo -D
  735. cd "$rendered_dir"
  736. git add .
  737. echo "Run git status and commit now!"
  738. git commit -am "$msg" && git push; cd "$source_dir"; git push
  739. echo "$site_url is live now!"
  740. }
  741. hgn ()
  742. {
  743. arg="$@"
  744. if [ -z $arg ]; then
  745. echo "Please give me a name!"
  746. fi
  747. # Create new post and edit with $EDITOR
  748. if [ -d ~/git/mysite/ ]; then
  749. posts_dir="$HOME/git/mysite/content/posts"
  750. cd "$HOME/git/mysite/"
  751. hugo new $posts_dir/$arg --editor $EDITOR\
  752. || $EDITOR $posts_dir/$arg
  753. fi
  754. }
  755. gbi ()
  756. {
  757. git branch --all --no-color |
  758. sed -e 's/\*/ /' |
  759. while read branch; do
  760. branch=${branch%% *}
  761. ref=$branch
  762. case $ref in
  763. */HEAD) continue;;
  764. remotes/*) color='magenta'; branch=${branch#remotes/};;
  765. *) color='yellow';;
  766. esac
  767. git log -1 --format=format:"%C($color)${branch}%C(reset) %s %C(blue)(%cr)%C(reset)" "$ref"
  768. done
  769. }
  770. isinstalled () {
  771. prog=$1
  772. if [[ $(command -v ${prog}) == "" ]]; then
  773. echo -e "${prog} is not installed!"
  774. return 1
  775. fi
  776. echo -e "${prog} is installed!"
  777. return 0
  778. }
  779. newest ()
  780. {
  781. /usr/bin/ls -Art $1* | tail -n 1
  782. }
  783. bbb ()
  784. {
  785. base64 < "$1" | tr -d '\n' | xclip
  786. }
  787. man() {
  788. LESS_TERMCAP_md=$'\e[01;31m' \
  789. LESS_TERMCAP_me=$'\e[0m' \
  790. LESS_TERMCAP_se=$'\e[0m' \
  791. LESS_TERMCAP_so=$'\e[01;44;33m' \
  792. LESS_TERMCAP_ue=$'\e[0m' \
  793. LESS_TERMCAP_us=$'\e[01;32m' \
  794. command man "$@"
  795. }
  796. andial() {
  797. # Make a phone call from connected android devices
  798. phone_number="$1"
  799. adb shell am start -a android.intent.action.CALL -d tel:$phone_number
  800. }
  801. macgen() {
  802. # mac generator
  803. dd if=/dev/random bs=2 count=3 2>/dev/null | perl -e '$hex = <>; $hex = unpack("H*", $hex) ; $hex =~ s/(..)(?!.?$)/$1:/g; print "$hex\n"'
  804. }
  805. kp() {
  806. # kill a process like opera, chrome
  807. local sum
  808. local items
  809. local app="$1"
  810. if [ -z "$app" ];
  811. then
  812. echo "First argument - pattern to grep from processes"
  813. else
  814. sum=0
  815. for i in `ps aux | grep -i "$app" | grep -v "grep" | awk '{print $6}'`
  816. do
  817. sum=$(($i + $sum))
  818. done
  819. sum=$(echo "scale=2; $sum / 1024.0" | bc)
  820. if [[ $sum != "0" ]]
  821. then
  822. echo "${fg[blue]}${app}${reset_color} is having ${fg[green]}${sum}${reset_color} MBs of RAM."
  823. for i in `ps aux | grep -v 'grep' | grep -i "$app" | awk '{print $2}'`
  824. do
  825. notify-send -i ${app} -t 1500 "process ${i} is gone!"
  826. kill -9 $i
  827. done
  828. else
  829. echo "There are no processes with pattern '${fg[blue]}${app}${reset_color}' are running."
  830. fi
  831. fi
  832. }
  833. ryt()
  834. {
  835. # record a youtube video from my screen
  836. today="$HOME/you/yt-"$(date +%F_%T)
  837. ffmpeg -f pulse -ac 2 -i default -f x11grab -r 30 -s 1920x1080 -i :0.0 -acodec pcm_s16le -vcodec libx264 -preset ultrafast -threads 0 -vf "drawtext=text='Follow me on  AbdullahToday  AbdullahToday  AbdullahToday  https\://abdullah.today':y=h-line_h-50:x=if(eq(t\,0)\,w\,if(lt(x\,(0-tw))\,w\,x-4)):fontsize=75:fontfile=/usr/share/fonts/nerd-fonts-complete/TTF/Go Mono Nerd Font Complete.ttf:fontcolor=white" $today.mkv
  838. }
  839. rtty()
  840. {
  841. # record my tty for youtube
  842. today="$HOME/you/yt-"$(date +%F_%T)
  843. ffmpeg -f pulse -ac 2 -i default -f fbdev -r 30 -i /dev/fb0 -acodec pcm_s16le -vcodec libx264 -preset ultrafast -threads 0 -vf "drawtext=text='Follow me on  AbdullahToday  AbdullahToday  AbdullahToday  https\://abdullah.today':y=h-line_h-50:x=if(eq(t\,0)\,w\,if(lt(x\,(0-tw))\,w\,x-4)):fontsize=75:fontfile=/usr/share/fonts/nerd-fonts-complete/TTF/Go Mono Nerd Font Complete.ttf:fontcolor=white" $today.mkv
  844. }
  845. rarea()
  846. {
  847. # Record an area of the screen. Hacksaw is the dependency.
  848. today="$HOME/you/yt-"$(date +%F_%T)
  849. hacksaw -n | IFS=+x read -r w h x y
  850. w=$((w + w % 2))
  851. h=$((h + h % 2))
  852. ffmpeg -v 16 -r 30 -f x11grab -s "${w}x${h}" -i ":0.0+$x,$y" -preset ultrafast -c:v h264 -pix_fmt yuv420p -crf 20 $today.mkv
  853. }
  854. rec4mobi()
  855. {
  856. # Record videos for mobile devices
  857. today="$HOME/you/mob-"$(date +%F_%T)
  858. ffmpeg -f pulse -ac 2 -i default -f x11grab -r 30 -s 1920x1080 -i :0.0 -acodec aac -b:a 320k -ar 48000 -vcodec libx264 -preset ultrafast -b:v 15M -threads 4 -pix_fmt yuv420p -cpu-used 0 $today.mp4
  859. }
  860. drd()
  861. {
  862. feh --bg-scale '/home/ak/pix/wall/collection/470768.jpg'
  863. }
  864. andvid()
  865. {
  866. # convert video mobile friendly
  867. # Don't foret to give output file with an extension
  868. video_file="$1"
  869. output_file="$2"
  870. ffmpeg -i $video_file -vcodec h264 -s 1280x720 $output_file
  871. }
  872. draw()
  873. {
  874. # floating window of $TERMINAL with specified geometry
  875. # Get geometry
  876. thickness=$(bspc config border_width)
  877. color=$(bspc config focused_border_color)
  878. hacksaw -ns $thickness -c $color | IFS=+x read -r w h x y
  879. # Add a new rule
  880. bspc rule -a \* -o state=floating rectangle="$((w - 2 * thickness))x$((h - 2 * thickness))+$x+$y"
  881. # Execute $TERMINAL
  882. $TERMINAL &
  883. }
  884. zal () {
  885. curl -s https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.csv
  886. }
  887. nowall()
  888. {
  889. awk '{print $4}' ~/.fehbg | xargs rm
  890. systemctl --user restart wallpaper.service
  891. }
  892. doips()
  893. {
  894. # docker containers IPs with IDs
  895. for ID in $(docker ps -q | awk '{print $1}');
  896. do
  897. IP=$(docker inspect --format="{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" "$ID")
  898. NAME=$(docker ps | grep "$ID" | awk '{print $NF}')
  899. printf "%s %s\n" "$IP" "$NAME"
  900. done
  901. }
  902. usbtr() {
  903. # Open connected android devices USB Tethering settings
  904. adb shell am start -n com.android.settings/.TetherSettings
  905. }
  906. geometry() {
  907. # Get a geometry for panel and other apps to put their window there
  908. if [ -x /usr/sbin/slop ]; then
  909. slop -f "%xx%y+%w+%h"
  910. else
  911. echo "Please install slop first..."
  912. fi
  913. }
  914. encme() {
  915. # encrypt files to myself with age
  916. recipient="$HOME/.ssh/id_ed25519.pub"
  917. files="$1"
  918. age -R $recipient $files > $files.age
  919. }