You are not logged in.
Updated script for downloading from tpb. Apparently they added another tracker and it resulted in issue with earlier script. Fixed now (Think so )
#!/usr/bin/bash
#
# v-k 2013
#
###
errorout() {
echo "error: $*" >&2;
echo
[[ -e "$tmp_dir" ]] && rm -r "$tmp_dir";
exit 1;
}
message() {
echo "usage: ${0##*/} pattern"; exit 1;
}
search_pb() {
local str cntr
str="$1"
cntr=$2
[[ -f "$tmp_dir/tpb.1.test.$cntr" ]] || curl -s "http://thepiratebay.sx/search/${str// /%20}/$cntr/7/0" > "$tmp_dir/tpb.1.test.$cntr"
sed -n '/class="detName"/ {p;n;n;p;n;p;n;n;p;n;p;}' "$tmp_dir/tpb.1.test.$cntr" > "$tmp_dir/tpb.2.test"
sed -n '/class="detName"/ s/.*>\(.*\)<\/a>/\1/p; n; s/^<a href="\(.*\)" title="Down.*/\1/p; n; s/.*Uploaded \(.*\)\ \;\(.*\), Size \(.*\)\ \;\(.*\),.*/\1 \2|\3\4/gp; n; s/[^0-9]//gp; n; s/[^0-9]//gp;' "$tmp_dir/tpb.2.test" > "$tmp_dir/tpb.result"
sed -i '1,${N;N;N;N;s/\n/|/g}' "$tmp_dir/tpb.result"
}
display_res() {
width=$(cut -d"|" -f1 "$tmp_dir/tpb.result" | wc -L)
divider="$(printf "%-$(($width+53))s" " ")"
i=1
printf "\n $(tput bold)$(tput setaf 3)%2.2b | %-${width}.${width}s | %11.11b | %9.9b | %8.8b | %6.6b |$(tput sgr0) \n" "# " "NAME (Pg #$((pg_cntr+1)))" "DATE" "SIZE" "SEEDS(!)" "LEECHS"
echo "${divider// /=}+"
while read NAME LINK DATE SIZE SEED LEECH; do
[[ ${#DATE} -ne 11 ]] && DATE="${DATE// / }"
printf " %2.2b | %-${width}.${width}s | %11.11b | %9.9b | $(tput setaf 2)%8.8b$(tput sgr0) | $(tput setaf 1)%6.6b$(tput sgr0) | \n" "$i" "$NAME" "$DATE" "$SIZE" "$SEED" "$LEECH"
((i++))
done < "$tmp_dir/tpb.result"
echo "${divider// /=}+"
}
download() {
IFS=","
for i in $sel; do
link="$(head -n $i "$tmp_dir/tpb.result" | tail -n 1 | cut -d"|" -f2)"
echo $link >> "$tmp_dir/links"
done
IFS="$IFS_BAK"
}
# main starts here
[[ -f /usr/bin/aria2c ]] || errorout "aria2c is needed for getting metadata from magnet links"
[[ $# -eq 1 ]] || message
tmp_dir="$(mktemp -d)"
cmd_arg="$1"
pg_cntr=0
while true; do
clear
search_pb "$cmd_arg" $pg_cntr
IFS_BAK="$IFS"
IFS="|"
display_res
IFS="$IFS_BAK"
echo
echo -n "Enter selection: "
read sel
[[ -z $sel ]] && errorout "Invalid/Empty choice !! exiting !!!"
[[ $sel = n ]] && { ((pg_cntr++)); continue; }
[[ $sel = b ]] && { ((pg_cntr--)); continue; }
download
echo
aria2c -q --bt-metadata-only --bt-save-metadata -i "$tmp_dir/links" &
pid=$!
while kill -0 $pid &> /dev/null; do
printf "[. ] Downloading torrents !!\r"
sleep .4s
printf "[ . ] Downloading torrents !!\r"
sleep .4s
printf "[ . ] Downloading torrents !!\r"
sleep .4s
printf "[ .] Downloading torrents !!\r"
sleep .4s
printf "[ . ] Downloading torrents !!\r"
sleep .4s
printf "[ . ] Downloading torrents !!\r"
sleep .4s
done
printf "[DONE] Downloading torrents !!\n\n"
break
done
rm -r "$tmp_dir"
"First learn computer science and all the theory. Next develop a programming style. Then forget all that and just hack." ~ George Carrette
Offline
Why is this better than tput? Because it is native where tput is a dependency?
Using raw ansi escape sequences is not better than using tput. tput queries the terminfo database and choses the correct escape sequence depending on the terminal, so tput is more portable than using raw sequences.
Offline
Inspired by this post, I wrote a function for my bashrc which checks which processes (number and command line) have a variable in their environment:
vgrep() {
for pro in $(grep -l $1 /proc/[0-9]*/environ 2>/dev/null); do
dir=$(dirname $pro)
printf "%4s %s\n" $(basename $dir) "$(cat $dir/cmdline 2>/dev/null)"
done
}
or, to add which actual variables in the environment match the search term (and to add some colors):
vgrep() {
for pro in $(grep -l $1 /proc/[0-9]*/environ 2>/dev/null); do
dir=$(dirname $pro)
printf "\033[38;5;78m[%0.4d]\033[38;5;111m %s\n" \
$(basename $dir) "$(cat $dir/cmdline 2>/dev/null)"
list="$(grep --binary-files=text -o "[A-Z0-9_]*$1[A-Z0-9_]*" \
$pro 2>/dev/null)"
echo -en " \033[38;5;229m"
for entry in $list; do
echo -n " $entry"
done
echo -e "\033[0m"
done
}
Last edited by Trilby (2013-05-21 16:36:22)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
OK, I've got a new one. It's REALLY simple, but helps me a lot.
I don't want my computer to install updates unless I know what's going to be updated (and I have time to deal with possible breakage), but I always want to at least download the updates. So, I changed my "update" alias to first download the packages and then ask me if I want to install them:
alias archupdate="sudo pacman -Syuw --noconfirm && sudo pacman -Syu"
Offline
I just print the list of files to be updated:
alias updates="pacman -Qqu --dbpath /tmp/checkup-db-jason"
Offline
OK, I've got a new one. It's REALLY simple, but helps me a lot.
I don't want my computer to install updates unless I know what's going to be updated (and I have time to deal with possible breakage), but I always want to at least download the updates. So, I changed my "update" alias to first download the packages and then ask me if I want to install them:
alias archupdate="sudo pacman -Syuw --noconfirm && sudo pacman -Syu"
Oh awesome. Yeah I started doing the same thing recently (cause I start update and then not pay attention / go do something else). I just use -Su for the second part though (plus my aur stuff after):
alias update='sudo pacman -Syuw --noconfirm && sudo pacman -Su && yaourt -Su --aur'
Offline
I just print the list of files to be updated:
alias updates="pacman -Qqu --dbpath /tmp/checkup-db-jason"
Or use 'checkupdates'.
Offline
jasonwryan wrote:I just print the list of files to be updated:
alias updates="pacman -Qqu --dbpath /tmp/checkup-db-jason"
Or use 'checkupdates'.
I usually do not revert to this sort of profanity, but... DAFUQ? Where does this come from?
2013-03-26 contrib: adding checkupdates Kyle Keen
Okay. Now that's cool.
Offline
I usually do not revert to this sort of profanity, but... DAFUQ? Where does this come from?
It's been around for a while https://bbs.archlinux.org/viewtopic.php … 5#p1072495
Some issues got fixed and here we have it in pacman-contrib :-)
Offline
jasonwryan wrote:I just print the list of files to be updated:
alias updates="pacman -Qqu --dbpath /tmp/checkup-db-jason"
Or use 'checkupdates'.
LOL. Thanks karol; it had never ocurred to me...
Offline
alias lsupdate="checkupdates && cower -u"
All the best,
-HG
Offline
jasonwryan wrote:I just print the list of files to be updated:
alias updates="pacman -Qqu --dbpath /tmp/checkup-db-jason"
Or use 'checkupdates'.
Which is why I love this thread - always find commands I didn't know existed
Ryzen 5900X 12 core/24 thread - RTX 3090 FE 24 Gb, Asus Prime B450 Plus, 32Gb Corsair DDR4, Cooler Master N300 chassis, 5 HD (1 NvME PCI, 4SSD) + 1 x optical.
Linux user #545703
/ is the root of all problems.
Offline
Inhibit KDE screensaver for xx minutes or hours
lightson.sh
while /bin/true; do qdbus org.freedesktop.ScreenSaver /ScreenSaver SimulateUserActivity > /dev/null; sleep 59s; done
lon.sh
timeout $1 lightson.sh
example
# lon.sh 55m
inhibits screensaver for 55 minutes.
comes in handy with flash or vlc videos
„Je verdinglichter die Welt, je dichter das Netz, das der Natur überworfen wurde, desto mehr beansprucht ideologisch das Denken, das jenes Netz spinnt, seinerseits Natur, Urerfahrung zu sein." Theodor W. Adorno [aus: Wozu noch Philosopie]
Offline
Wouldn't this be cleaner:
xset s off
sleep $1
xset s on
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Wouldn't this be cleaner:
xset s off sleep $1 xset s on
doesn'twork for me
„Je verdinglichter die Welt, je dichter das Netz, das der Natur überworfen wurde, desto mehr beansprucht ideologisch das Denken, das jenes Netz spinnt, seinerseits Natur, Urerfahrung zu sein." Theodor W. Adorno [aus: Wozu noch Philosopie]
Offline
This one is very simple, but It's useful to me:
alias getchmod="stat --format %a $1"
If it ain't broke, you haven't tweaked it enough.
Offline
Aliases don't take arguments ;P
You can also use
alias getchmod='stat --format "%n %a"'
$ getchmod foo test*
foo 644
test1 644
test2 644
test3 644
or use function to get a nicer formatting:
gmod () { stat --format "%n %a" $* | column -t; }
$ gmod foo test*
foo 644
test1 644
test2 644
test3 644
Offline
Put a clock in the upper right corner of shell
while sleep 1
do tput sc
tput cup 0 $(($(tput cols)-29))
date
tput rc
done &
Offline
Put a clock in the upper right corner of shell
while sleep 1 do tput sc tput cup 0 $(($(tput cols)-29)) date tput rc done &
Love it - just added it to my custom bash startup
Ryzen 5900X 12 core/24 thread - RTX 3090 FE 24 Gb, Asus Prime B450 Plus, 32Gb Corsair DDR4, Cooler Master N300 chassis, 5 HD (1 NvME PCI, 4SSD) + 1 x optical.
Linux user #545703
/ is the root of all problems.
Offline
Aliases don't take arguments ;P
-snip-
I'm not that great with bash, but as far as I know it works for me.
[mid-kid@schoolrocket ~]# alias getchmod="stat --format %a $1"
[mid-kid@schoolrocket ~]# getchmod
stat: missing operand
Try 'stat --help' for more information.
[mid-kid@schoolrocket ~]# getchmod Desktop/
755
If it ain't broke, you haven't tweaked it enough.
Offline
Aliases simply ignore positional arguments. Yes, you still have to supply arguments, because the computer can't read your mind which file(s) you want to stat.
Try the examples I posted to see for yourself. Try changing
gmod () { stat --format "%n %a" $* | column -t; }
to an alias - it won't work because the arguments are expected to come in the middle.
In getchmod alias the arguments come at the end, so this creates the illusion that aliases can take arguments.
Edit:
In my example
alias getchmod='stat --format "%n %a"'
$ getchmod foo test*
foo 644
test1 644
test2 644
test3 644
'getchmod' alias gets expanded to 'stat --format "%n %a"' so the above command is identical to
$ stat --format "%n %a" foo test*
'stat' needs an argument, so running just
$ stat --format "%n %a"
does not work.
Last edited by karol (2013-06-01 14:39:17)
Offline
Just a simple alias for finding a running process as it's something I have to do frequently.
alias fp="ps aux|grep -v grep|grep -i $1"
Offline
Just a simple alias for finding a running process as it's something I have to do frequently.
alias fp="ps aux|grep -v grep|grep -i $1"
Try 'pgrep'.
Offline
ill wrote:Just a simple alias for finding a running process as it's something I have to do frequently.
alias fp="ps aux|grep -v grep|grep -i $1"
Try 'pgrep'.
and instead of doing grep -v grep, try grep -i [f]irefox -- put first char in square brackets of whatever process you're trying to find.
"First learn computer science and all the theory. Next develop a programming style. Then forget all that and just hack." ~ George Carrette
Offline
Put a clock in the upper right corner of shell
while sleep 1 do tput sc tput cup 0 $(($(tput cols)-29)) date tput rc done &
If you use urxvt I think there's a perl extension that will provide that, too.
There are probably pros and cons of the two approaches - I used to use it but stopped so it must have had some irritating side effect that this approach may not have.
But thought it worth mentioning anyway.
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline