You are not logged in.
Get info from whatever package owns a file:
#!/bin/sh package=$(pacman -Qqo "$1") pacman -Qi $package
Why not
pacman -Qi $(pacman -Qqo $@)
or use expac if you want e.g. just the name & description:
$ expac "%n: %d" -Q $(pacman -Qqo date time)
coreutils: The basic file, shell and text manipulation utilities of the GNU operating system
time: Utility for monitoring a program's use of system resources
Offline
AaronBP wrote:Get info from whatever package owns a file:
#!/bin/sh package=$(pacman -Qqo "$1") pacman -Qi $package
Why not
pacman -Qi $(pacman -Qqo $@)
No particular reason other than readability. I used $1 because listing -Qi output for multiple files at once didn't seem particularly useful, and the command already takes about 5 seconds on this crap machine.
or use expac if you want e.g. just the name & description:
$ expac "%n: %d" -Q $(pacman -Qqo date time) coreutils: The basic file, shell and text manipulation utilities of the GNU operating system time: Utility for monitoring a program's use of system resources
That's interesting; I like that. I'd never heard of expac. I'll try it out.
Offline
listing -Qi output for multiple files at once didn't seem particularly useful, and the command already takes about 5 seconds on this crap machine.
pacman runs slow just the first time you call it, because it loads the database into memory.
The second time you run it, it should be about 0.5 sec. :-)
$ time pacman -Qi $(pacman -Qqo date time) >/dev/null
real 0m0.441s
user 0m0.090s
sys 0m0.087s
You can always pipe the output to 'less' if you don't want the terminal to get flooded with info that just scrolls by.
Offline
If you insist on using a script, that's fine by me, but I keep such oneliners in ~/.bashrc.
Offline
I've still got a few functions in my ~/.bashrc, but I've gotten into the habit of putting everything in ~/bin. There are a couple advantages:
The only thing that uses ~/.bashrc is bash. Things that are only used in an interactive shell anyway, like pacinfo above, could go in ~/.bashrc anyway, but other scripts I might otherwise run in a launcher, and also it would be a pain to have to move everything over if I got a bug and suddenly decided to switch to, say, zsh.
It could potentially get difficult to keep up with ~/.bashrc very quickly. I can see all my scripts and get an idea of what they do from their name by typing ls ~/bin. It's self-documenting and easier to maintain.
Offline
Makes sense, just remember that e.g. dash doesn't have (among other things) arrays or process substitution :-)
Offline
Get your current external IP address:
extip
#!/usr/bin/env python
# Print your external IP address to stdout
import urllib
def main():
data = urllib.urlopen('http://checkip.dyndns.org/').read()
print data.partition('Address:')[2].partition('<')[0].strip()
if __name__ == '__main__':
main()
Offline
It should say '#!/usr/bin/env python2' otherwise you get an error:
File "./test1", line 8
print data.partition('Address:')[2].partition('<')[0].strip()
^
SyntaxError: invalid syntax
python3 is the default on Arch.
'curl ifconfig.me' does the same thing as your script.
Offline
A bit more of a reliable alternative:
alias ipinfo='dig myip.opendns.com @resolver1.opendns.com +short'
Offline
Or
curl icanhazip.com
... or role your own on a free Heroku instance:
<?php
header('Content-Type: text/plain');
echo $_SERVER['HTTP_X_FORWARDED_FOR'] . "\n";
?>
Offline
May have posted this before. May post it again. Very much a work in progress.
Basically made to make my life easier when compiling packages over ssh on my phone (via connectbot), then became a feature of my everyday life. Unless you use abs/aur on a regular basis, and have devtools installed, it probably won't be of any use to you.
Last edited by WorMzy (2012-09-14 10:59:47)
Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD
Making lemonade from lemons since 2015.
Offline
Use scrot, omup (an ompldr command line tool available in the AUR) and xclip to take a screenshot, upload it to ompldr, and copy the url to your clipboard:
scrot /tmp/screenshot.png && omup /tmp/screenshot.png | xclip -in
Offline
imgupload is a bit like my earlier in the thread imgreview application. It uses feh and its actions to cycle through a set of images and queue them for ftp upload.
It is mainly designed to be wrapped for different sites (eg I have a devupload wrapper for deviantart).
It uses ncftp and their login file for sites. This is not ideal and once I've finally sorted out my passwords system, I'll hopefully add a hook in for that. Up 'til then I use a 600 permission file in the format the ncftp recognises.
It uses a separate script to remove the queued images which is listed afterwards.
I only finished it yesterday and have only used it twice, so there could be undiscovered issues in with it.
#!/bin/bash
#
# imgupload
#
# Enable to go through a folder of images and allow select
# for upload to a passed in ftp site.
#
# $1 - ftp address to upload any selected images to.
#
# Depends on feh, ncftp
#
#
# TODO
# *) pass in a gpg file to get the username etc.
THIS=$(basename $0)
TRGDIR=.
SRC=.
UPLOAD=on
# Usage function
usage () { echo "Usage: $THIS [-h] [-s source_dir] [-u off/on] user_login_file" ; }
# Dislays help information
help () {
cat << ENDHELP
$THIS: Uses feh(1) to sort through a list of images in the current directory.
Using feh's ACTIONS the user can upload the displayed image to
the supplied ftp site. The image will be queued for uploading. Once
The user has escaped from feh(1), the uploading will start and be
carried out by ncftp.
The site and logon details are specied in a file. The details of this
file's format can be found at ncftpput(1). The name of the file must
be passed in as the first parameter.
When an image is displayed, pressing <ENTER> will select the file for
upload.
Normal feh commands are all usable.
<ESCAPE> is used to exit feh, and the script will then start the upload
process.
To view running or spooled upload jobs, use:
$ ncftpbatch -l
Options:
-s directory changes the source directory for the images.
-h display this help and exit
-u off/on whether or not to start the upload immediately.
Default: on
ENDHELP
}
# getopts
while getopts "s:hu:" opt; do
case $opt in
s ) SRC="$OPTARG" ;;
h ) help
exit 0 ;;
u ) UPLOAD="$OPTARG" ;;
\? ) usage
exit 1
esac
done
shift $(($OPTIND -1))
# Check we have an upload site:
if [ -z "$@" ]; then
usage
exit 1
else
USER="$1"
fi
# Build action command
ACTION="--draw-actions --action 'ncftpput -f $USER -bb $TRGDIR %f'"
ACTION="$ACTION --action1 'unqimgupload %n'"
# feh command
eval feh -dF $ACTION "${SRC}"/*.{jpg,JPG,png,PNG,gif,GIF}
# Uploader organiser, keeps things polite
if [ "$UPLOAD" = on ]; then
ncftpbatch -d
fi
ncftpbatch -l
# vim:set sts=4 ts=4 sw=4 ft=sh et:
#!/bin/bash
#
# unqimgupload
#
# Unqueues any queued upload of a specified file, that's waitning to be uploaded
# in an ncftp upload. Mainly used to unenqueue images as queued by
# imgupload.
#
# TODO
# *) tighten up and improve error handling
# *) add verbose option
QDIR="$HOME/.ncftp/spool"
FILE=$(grep -l $1 $QDIR/[px]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-*)
if [ -e "$FILE" ]; then
rm "$FILE"
fi
# vim:set sts=4 ts=4 sw=4 ft=sh et:
EDIT: it was pointed out to me that I'd missed some quoting of variables out. I've added them, thanks.
Last edited by skanky (2012-09-12 12:35:01)
"...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
Record part of your desktop using ffmpeg.
Depends on xorg-xwininfo.
What needs to be done: record application sounds using alsa.
If you want to record microphone on a seperate file you have to first use "--file name" and then "--mic-sep" so that video/audio have the same name.
It's my first "real" script so be aware.
#!/bin/bash
filename=/tmp/screencap-$(date +"%a-%d-%b-%H%M").mkv
audio=''
extrargs=''
display=0.0
usage(){
echo "Usage: $(basename $0) [options]"
echo 'Options:'
echo ' --file <filename> : save to filename,'
echo ' --mic : record microphone audio,'
echo ' --mic-sep : record microphone audio on a seperate file,'
echo ' --print : print ffmpeg command,'
echo ' --display : specify the display to record,'
echo ' -h|--help : print this help message'
echo ' Any other option will be passed directly to ffmpeg.'
}
#Process input
while [[ $1 ]]; do
case "$1" in
'--file') filename=$2; shift ;;
'--print') only_print=0 ;;
'--mic') [[ -z audio ]] && audio='-f alsa -ac 2 -i hw:0,0' ;;
'--mic-sep') [[ -z $audio ]] && audio="-f alsa -ac 2 -i hw:0,0 -acodec flac $filename.flac" || audio+=" $filename.flac" ;;
'--display') display=$2; shift ;;
'-h'|'--help') usage; exit 0;;
*) extrargs+=("$1") ;;
esac
shift
done
#Get window info
## 0- Upper-left X, 1- Upper-left Y, 2- Width, 3- Height
win=( $(xwininfo -frame | awk 'BEGIN{FS=":"} /Height|Width|Absolute upper-left/ {gsub(/[[:space:]]/,"",$2); print $2}') )
#Get the screen size
## 1- Width 2- Height
scr=( $(xrandr | awk '/*/ {gsub(/x/, " ", $1); print $1}' ) )
## Record only what is visible on the screen ( or ffmpeg will fail )
[[ ${win[0]} -lt 0 ]] && let win[2]+=${win[0]} && let win[0]=0
[[ ${win[1]} -lt 0 ]] && let win[3]+=${win[1]} && let win[1]=0
let "ex=${win[0]}+${win[2]}"
let "ey=${win[1]}+${win[3]}"
[[ $ex -gt ${scr[0]} ]] && let "win[2]-=$ex-${scr[0]}"
[[ $ey -gt ${scr[1]} ]] && let "win[3]-=$ey-${scr[1]}"
#Make sure width/height are divisable by 2 ( or ffmpeg may fail )
let rem=${win[2]}%2
let win[2]+=$rem
rem=0
let rem=${win[3]}%2
let win[3]+=$rem
command="ffmpeg $audio -f x11grab -s ${win[2]}x${win[3]} -r 35 -i :$display+${win[0]},${win[1]} -preset ultrafast -vcodec libx264 ${extrargs[@]} $filename"
[[ $only_print ]] && echo $command || $command
Offline
findinfile
Pure BASh.
#!/bin/bash
[ ${#} -lt 2 ] && { printf "${0} <string> <file(s)>\n"; exit 1; }
str="${1}"; shift; files=( "${@}" ); h=0
for ((i=0; i < ${#files[@]}; i++)); do
file="${files[${i}]}"; j=0; k=1; m=
[ ${h} -lt ${#file} ] && h=${#file} || \
[ ${h} -gt ${#file} ] && for ((l=0;l < ${h} - ${#file}; l++)); do m+=" "; done
printf "${file}${m}\r"
[ -r "${file}" ] || \
{ printf "\e[1m${file}\e[0m is \e[31;1mnot readable\e[0m\n" && continue; } && \
[ -d "${file}" ] || \
while read fstr; do ((j++))
[[ "${fstr}" =~ "${str}" ]] && { [ ${k} -eq 1 ] && \
printf "\e[1m${file}\e[0m\n" && ((k=0)) || \
printf "\t${j}: ${fstr/${str}/\e[32;1m${str}\e[0m}\n"; }
done < "${file}"
done
printf "\n"
Last edited by ResXaoC (2012-09-25 16:33:05)
Offline
tl;dr
Why not grep?
Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD
Making lemonade from lemons since 2015.
Offline
Becouse of using only BASh.
Last edited by ResXaoC (2012-09-23 21:20:15)
Offline
Merging with the Handy Command Line Utilities thread...
Offline
My internet radio script. Has some coloring and you can change station by pressing q to exit mplayer and choose another station.
If no response is given atthe prompt in 5secs, it exits.
Also pressing 'c' while playing a station starts capturing the stream in pwd as stationname_time_date.mp3
#!/bin/bash
#black=`tput setaf 0`
#red=`tput setaf 1`
#green=`tput setaf 2`
#yellow=`tput setaf 3`
#blue=`tput setaf 4`
#magenta=`tput setaf 5`
cyan=`tput setaf 6`
white=`tput setaf 7`
norm=`tput sgr0`
bold=`tput bold`
#ulbegin=`tput smul`
#ulend=`tput rmul`
ser="$white"
name="$bold$cyan"
stations=(
Pvibe:ambient="http://67.212.233.124:8008"
Pvibe:house="http://67.212.233.124:8006"
Pvibe:dance="http://67.212.233.124:8000"
Pvibe:psycho="http://67.212.233.124:8010"
Pvibe:trance="http://67.212.233.124:8004"
Pvibe:breakbeat="http://67.212.233.124:8012"
Pvibe:dubstep="http://67.212.233.124:8014"
Pvibe:hardcore="http://67.212.233.124:8002"
Nirvana="http://91.121.72.50:9106"
Smooth="http://uk1.internet-radio.com:4086"
Zenradio="http://zenradio.fr:8800"
RadioParadise="http://stream-sd.radioparadise.com:9000/rp_128.mp3"
)
#show_inf () {
# sed -n '/Name/,/Bitrate/ p' $tfile
# }
while(true); do
index=0
echo
for i in "${stations[@]}"; do
echo ${ser}$index.${norm} ${name}${i%%=*}${norm}
index=$[index+1]
done
echo
read -p "${cyan}Station:${norm} " sta
echo
capture="-capture -dumpfile ${stations[$sta]%%=*}_`date "+%T_%F"`.mp3"
#tfile=`mktemp`
mplayer -vc null -vo null -nolirc -msglevel all=4 ${capture} -msgcolor `echo ${stations[$sta]} | cut -d '=' -f2`
echo -ne "${cyan}\nPress Entr to change station ${norm}"
read -t 5
[[ $? -gt 128 ]] && { echo && exit 0; }
#rm $tfile
unset -v index sta capture
done
exit 0
I was actually trying to redirect the mplayer output to a tempfile and sed out only the station info lines.
But as long as mplayer isn't put in the bg or it exits, I cant run sed.
Anyway to do that?
Last edited by debdj (2012-09-24 13:55:48)
Offline
I was actually trying to redirect the mplayer output to a tempfile and sed out only the station info lines.
But as long as mplayer isn't put in the bg or it exits, I cant run sed.
Anyway to do that?
I'm using awk with different field separators, grepping for Name (station name) and ICY Info: StreamTitle (the song title):
radio()
{
cd /home/karol/music/radio/ && mplayer -playlist $(sed -n "$1"p radiolist) 2>&1 | awk -F " : |='|';" '/Name/ {print $2} /ICY Info/ {print $2}'
}
The radio stations list:
$ cat /home/karol/music/radio/radiolist
RadioParadise.pls
TheEagle.pls
absolute_80s.pls
absolute_90s.pls
absolute_classic_rock.pls
absolute_radio.pls
groovesalad.pls
illstreet130.pls
poptron.pls
raggakings.m3u
rautemusik.pls
rmffm.pls
secretagent.pls
skyfm80s.pls
sonicuniverse.pls
u80s.pls
wcpe.pls
wfmu.pls
Usage and output:
$ radio 2
181.fm - The Eagle (Your Home For REAL Classic Rock!)
Rod Stewart - Maggie May
Mplayer output I had to filter:
$ mplayer -playlist $(sed -n 2p radiolist)
Unknown entry type Version=2
MPlayer2 UNKNOWN (C) 2000-2012 MPlayer Team
Can't open joystick device /dev/input/js0: No such file or directory
Can't init input joystick
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
Playing http://174.36.241.224:10108/.
Resolving 174.36.241.224 for AF_INET6...
Couldn't resolve name for AF_INET6: 174.36.241.224
Connecting to server 174.36.241.224[174.36.241.224]: 10108...
Name : 181.fm - The Eagle (Your Home For REAL Classic Rock!)
Genre : Classic Rock
Website: http://www.181.fm
Public : yes
Bitrate: 128kbit/s
Cache size set to 320 KBytes
Cache fill: 0.00% (0 bytes)
ICY Info: StreamTitle='Rod Stewart - Maggie May';StreamUrl='http://www.181.fm';
Cache fill: 15.00% (49152 bytes)
Detected file format: Audio only
Selected audio codec: MPEG 1.0/2.0/2.5 layers I, II, III [mpg123]
AUDIO: 44100 Hz, 2 ch, s16le, 128.0 kbit/9.07% (ratio: 16000->176400)
AO: [alsa] 48000Hz 2ch s16le (2 bytes per sample)
Video: no video
Starting playback...
A: 0.7 (00.7) of -0.0 (unknown) 1.9% 55%
:-)
Last edited by karol (2012-09-24 14:12:00)
Offline
@karol Thanks.
What I thought was as long as a command doesn't exit, the one at the receiving end of the pipe doesn't get the output.
I just changed the mplayer line to
mplayer -vc null -vo null -nolirc -msglevel all=4 ${capture} -msgcolor `echo ${stations[$sta]} | cut -d '=' -f2` 2>&1 | sed -n '/Name/,/Bitrate/ p'
Offline
…because sometimes unclutter is not enough
┌─[Centurion ~]
└─╼ less Scripts/mouse
#!/bin/bash
# toggle the rodent
rat=$(awk '/Mouse/ { sub(/id=/,""); print $7 }' <(xinput --list))
case $1 in
on) xinput enable "$rat"
;;
off) xinput disable "$rat"
;;
*) printf '%s\n' 'on OR off…'; exit 1
;;
esac
Offline
Sweet ... I wasn't familiar with xinput. But FYI, "Mouse" would need to be adjusted for laptops with touch/trackpads.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
# Download an imgur album
# Usage: imgur-album-dl $url$
function imgur-album-dl() {
curl -s "$1" | grep 'data-src="http://i.imgur.com/' | sed -re 's|.*(http://i.imgur.com/[^\.]*\....).*|\1|; s|s\.|.|' | wget -i -
}
# Download a facebook album
# Usage:
# fb-album-dl login $email$ $password$ ## login to facebook
# fb-album-dl logout ## logout from facebook
# fb-album-dl $url$ ## download album at $url$
function fb-album-dl() {
COOKIES='/tmp/cookies.txt'
case "$1" in
'login')
USER_AGENT='Firefox/4.0'
EMAIL="$2"
PASS="$3"
curl -X GET 'https://www.facebook.com/home.php' --user-agent $USER_AGENT --cookie $COOKIES --cookie-jar $COOKIES --location # redirects to https://login.facebook.com/login.php
curl -X POST 'https://login.facebook.com/login.php' --user-agent $USER_AGENT --data-urlencode "email=${EMAIL}" --data-urlencode "pass=${PASS}" --cookie $COOKIES --cookie-jar $COOKIES
curl -X GET 'https://www.facebook.com/home.php' --user-agent $USER_AGENT --cookie $COOKIES --cookie-jar $COOKIES
;;
'logout')
rm $COOKIES
;;
*) curl -s -b "$COOKIES" "$1" | grep -Eo 'http[s]?://[^/]+photos[^/]+[^\.]*_a.[^");]*' | sed 's/_a./_n./g' | wget -i -
esac
for var in COOKIES USER_AGENT EMAIL PASS; do unset $var; done
}
Some functions I made. May look ugly, I'm not such an expert at scripting. If you have suggestions I would appreciate.
Offline