Skip to content

Commit 451aea5

Browse files
author
Paul Römer
committed
several bash functions and scripts added
0 parents  commit 451aea5

File tree

7 files changed

+105
-0
lines changed

7 files changed

+105
-0
lines changed

bash_func/compression.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ex () {
2+
if [ -f $1 ] ; then
3+
type=$(file -0 $1|cut -d " " -f2);
4+
case $type in
5+
bzip2) tar xjf $1 ;;
6+
gzip) tar xzf $1 ;;
7+
rar) unrar e $1 ;;
8+
zip) unzip $1 ;;
9+
7z) 7z x $1 ;;
10+
*) echo "'$1' cannot be extracted via extract()" ;;
11+
esac
12+
else
13+
echo "'$1' is not a valid file"
14+
fi
15+
}

bash_func/netinfo.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#netinfo - shows network information for your system
2+
netinfo ()
3+
{
4+
echo "--------------- Network Information ---------------"
5+
/sbin/ifconfig | awk /'inet addr/ {print $2}'
6+
/sbin/ifconfig | awk /'Bcast/ {print $3}'
7+
/sbin/ifconfig | awk /'inet addr/ {print $4}'
8+
/sbin/ifconfig | awk /'HWaddr/ {print $4,$5}'
9+
myip=`lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | sed '/^$/d; s/^[ ]*//g; s/[ ]*$//g' `
10+
echo "${myip}"
11+
echo "---------------------------------------------------"
12+
}

bash_func/readme.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
= bash functions =
2+
3+
Source these files to use them within bash scripts or on commandline:
4+
5+
# source additional commands
6+
for s in ${HOME}/.bashrc.d/*.sh ; do
7+
test -r $s && . $s
8+
done

bash_scripts/ma

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
echo "scale=2; $*" | bc -l

bash_scripts/readme.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
= bash scripts =
2+
3+
Put these scripts into a folder known by your $PATH. Some may overlay existing executables.

bash_scripts/translate

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
# gtranslate.sh
3+
# Translate using Google Translate Ajax API:
4+
# http://ajax.googleapis.com/ajax/services/language/translate?v=1.0 \
5+
# &langpair=en|es&q=hello+world
6+
# More Info: http://code.google.com/apis/ajaxlanguage/documentation/
7+
# ksaver (at identi.ca), March 2010.
8+
# Licence: Public Domain Code.
9+
10+
progname=$(basename $0)
11+
12+
if [ -z "$1" ]
13+
then
14+
echo -e "Usage: $progname lang1 lang2 'string of words to translate...'"
15+
echo -e "Usage: $progname 'string of words to translate...' (de->en)"
16+
echo -e "Example: $progname en de 'Hello World!'\n"
17+
exit
18+
fi
19+
20+
if [ -z "$2" ];
21+
then
22+
FROM="de";
23+
TO="en";
24+
else
25+
FROM="$1"
26+
TO="$2"
27+
fi
28+
29+
# Google Translate Ajax API Url
30+
TRANSURL='http://ajax.googleapis.com/ajax/services/language/translate?v=1.0'
31+
LANGPAIR="$FROM|$TO"
32+
shift 2
33+
34+
# Parse string to translate, change ' ' to '+'
35+
# STRING: String to translate.
36+
STRING="$@"
37+
PSTRING=$(echo "$STRING" |tr ' ' '+')
38+
39+
# Get translation
40+
RESPONSE=$(/usr/bin/env curl -s -A Mozilla \
41+
$TRANSURL'&langpair='$LANGPAIR'&q='$PSTRING)
42+
43+
echo -n "$progname> "
44+
# Parse and clean response, to show only translation.
45+
echo "$RESPONSE" |cut -d ':' -f 3 |cut -d '}' -f 1

bash_scripts/vim

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
if [ -n $1 ];
4+
then
5+
if [[ $1 == *:* ]];
6+
then
7+
file=$(echo $1 | cut -d ":" -f1);
8+
line=$(echo $1 | cut -d ":" -f2);
9+
10+
echo $file
11+
echo $line
12+
/usr/bin/vim +$line $file
13+
else
14+
/usr/bin/vim $*;
15+
fi
16+
else
17+
/usr/bin/vim $*;
18+
fi;
19+

0 commit comments

Comments
 (0)