scripts

My personal collection of scripts
git clone git://src.gearsix.net/scripts
Log | Files | Refs | Atom | README | LICENSE

commit b191a161d12f954b6a74f5e1527d2e3c909c9973
Author: GeaRSiX <gearsix@tuta.io>
Date:   Mon, 12 Nov 2018 21:45:30 +0000

✨ initial commit

Diffstat:
Acpc.sh | 8++++++++
Adepreciated/touchn.sh | 18++++++++++++++++++
Aflac2mp3.sh | 10++++++++++
Agfind.sh | 7+++++++
Amkdcp.sh | 16++++++++++++++++
Amkdmv.sh | 16++++++++++++++++
Amkdnvim.sh | 11+++++++++++
Aopenurl.sh | 10++++++++++
Ashh.sh | 10++++++++++
Astrindex.sh | 16++++++++++++++++
Astrlen.sh | 22++++++++++++++++++++++
Axopen.sh | 23+++++++++++++++++++++++
12 files changed, 167 insertions(+), 0 deletions(-)

diff --git a/cpc.sh b/cpc.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# ~/scripts/cpc.sh +# copies the contents of file $1 to file $2 +# e.g.$ cpc file1.txt file2.txt + +touch $2 +echo "$(cat $1)" > $2 + diff --git a/depreciated/touchn.sh b/depreciated/touchn.sh @@ -0,0 +1,18 @@ +#DEPREICATED +# found out you could just use "touch ./file{1..13}" + +#!/bin/bash +# ~/scripts +# create $2 files name $1 appended with 1 to $2 +# e.g$ touchn "song" 13 # creates song1...song13 in curr_dir + +# if no $2 +if [ -z $2 ]; then + echo "ERROR! touchn: Specify number of files to touch in \$2"; + return 1; +fi + +for i in $(seq 0 $2); do + touchn "$1$i"; +done + diff --git a/flac2mp3.sh b/flac2mp3.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# ~/scripts/flac2mp3.sh +# converts .flac to .mp3 +# DEPENDENCIES: requires ffmpeg +# e.g.$ flac2mp3 ./album + +for file in $1/*.flac; do + ffmpeg -i "$file" -qscale:a 0 "${file[@]/%flac/mp3}" +done + diff --git a/gfind.sh b/gfind.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# ~/scripts +# find files containing string $2 in directory/file $1 +# e.g.$ gfind dogs/ "shades" + +grep -rnw $1 -e $2 #recursive, print line #, match whole word + diff --git a/mkdcp.sh b/mkdcp.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# ~/scripts +# make a directory and copy files into it +# e.g.$ mkdcp ~/new-dir ~/var/tmp/file1 ~/var/tmp/file2 ... + +#mkdir $1 +dir=$1; +mkdir -p $dir +shift; + +#cp files into $1 +for file in $@; do + cp $file $dir; + shift; +done + diff --git a/mkdmv.sh b/mkdmv.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# ~/scripts +# make a directory and move files into it +# e.g.$ mkdmv ~/new-dir ~/var/tmp/file1 ~/var/tmp/file2 ... + +#mkdir $1 +dir=$1; +mkdir -p $dir +shift; + +#cp files into $1 +for file in $@; do + mv $file $dir; + shift; +done + diff --git a/mkdnvim.sh b/mkdnvim.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# ~/scripts +# Makes directory $1 and opens file $2 using nvim +# +# mkdnvim <new_dir> <filename> +# e.g.$ mkdnvim ~/new file #creates ~/new/file and nvim into it + +mkdir $1; +cd $1; +touch $2; +nvim $2; diff --git a/openurl.sh b/openurl.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# ~/scripts +# script for opening .url files +# e.g.$ openurl link.url +# http://www.danielbrice.net/blog/opening-url-file-like-a-pro/ + +URL=$(cat "$1" | grep "URL=" | cut -d= -f2) +echo -e "xdg-open $URL" +xdg-open "$URL" &> /dev/null + diff --git a/shh.sh b/shh.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# ~/scripts +# run a terminal command and send stdout to /dev/null +# +# shh cmd +# +# @TODO add autocomplete + +$@ &>/dev/null & + diff --git a/strindex.sh b/strindex.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# ~/scripts +# finds the starting index of a substring in a string +# index returned ranges from 0 - (string length) +# e.g.$ strindex "cat" "the cat sat on the mat" #returns 4 + +#swaps argument (strindex "cat on mat" "mat") +if [[ -z $3 && $3 == "-r" ]]; then + x="${1%%$2*}" + [[ "$x" = "$1" ]] && echo "ERROR! strindex(): Could not find $2 in $1" || echo "${#x}" +#standard usage (see e.g.$) +else + x="${2%%$1*}" + [[ "$x" = "$2" ]] && echo "ERROR! strindex(): could not find $1 in $2" || echo "${#x}" +fi + diff --git a/strlen.sh b/strlen.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# ~/scripts +# echo's the length of a string +# e.g.$ strlen "my di-" + +strU8DiffLen () { + local bytlen oLang=$LANG oLcAll=$LC_ALL + LANG=C LC_ALL=C + bytlen=${#1} + LANG=$oLang LC_ALL=$oLcAll + return $(( bytlen - ${#1} )) +} + +for string in $1; do + strU8DiffLen "$string" + printf " - %-$((14+$?))s is %2d chars length, but use %2d bytes\n" \ + "'$string'" ${#string} $((${#string}+$?)) +done + +#string=$1 +#length=${#string} +#echo "$length" diff --git a/xopen.sh b/xopen.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# ~/scripts +# open file in xserver (doesn't support multiple files at once) +# +# xopen file [-shh, -shhh] +# -shh, -shhh # send stdout to /dev/null +# +# $lazymode=xo +# +# @TODO add autocomplete + +for last_arg; do true; done; +# check for shhh +if [[ $last_arg == "-shh" || $last_arg == "-shhh" ]]; then + args=( "$@" ) # get all args + unset "args[${#args[@]}-1]" # remove last arg + + # all remaining args = files to open (shh mode) + xdg-open "$args" &>/dev/null +#standard +else + xdg-open "$@" +fi