Dumping strings from websites with curl is no big thing actually:
mycitytemp=$(curl -s ${myweatherservice} | grep foo | awk -F bar '{print $7}' | tr -d baz)
Depending on the website, it might occasionally be more convenient to use a text web browser though.
]]>curl $url | $longish_pipeline1
curl $url | $longish_pipeline2
curl $url | $longish_pipeline3
curl $url | $longish_pipeline4
could become:
curl $url > /tmp/some_tempfile
$longish_pipeline1 /tmp/some_tempfile
$longish_pipeline2 /tmp/some_tempfile
$longish_pipeline3 /tmp/some_tempfile
$longish_pipeline4 /tmp/some_tempfile
rm /tmp/some_tempfile
This would save a lot of wasted network bandwidth and downloading time.
But my comment that grep + tr + awk + tr = awk means that your entire "longish
pipeline" of commands could be replaced by a single call to awk. This would
require learning a bit more about how to use awk well - and for practical
purposes the efficiency benefit would not be huge.
So replacing the multiple calls to curl seems like a more important
consideration.
Once I looked for a (simple) weather script to pipe icons to dzen. "shaman" was not my taste, and I couldn't find any other. So I thought, it mustn't be too difficult to write one myself. And that’s now, what has come out of it – the mws (mito’s wx scripts) collection!
Finally they became four, from simple to complex, hope you don’t mind. Also that I became pretty garrulous by spending much effort on comments. But NP, I know all of you guys cope with Bash. Hence the first you would probably do is to eridicate half of the code, or even rewrite it.
Anyway for those who find the scripts useful, help yourself and adapt them to your needs. Yet there’re cases for parsing weather data from NWS, OMW, and yr.no, feel free to add another service. Or to localize a script for your language. – If there aren’t icons that can’t be downloaded as a whole set, one of the scripts shows how to download and convert the current icon on the fly (however I wished dzen supports PNG).
Do you know if it is possible to "to import variables" into the xmobar config file (xmobarrc). By import I mean that I keep a set of colors in both a Haskell module (for use in xmonad config) and the same colors in a shell script and I would like to import either one of them into xmobarrc so I can do specify base02 instead of #00a244. This would allow me to keep all xmobar+trayer+xmonad colors located a central place (I change color schemes on the fly).
The syntax of xmobarrc looks like Haskell, but that doesn't mean I can import a Haskell module. And if it is a text file with custom syntax (and a custom parser) it will of course not allow me to source a file like in a shell script.
]]># pop-up calendar for dzen
#
# based on (c) 2007, by Robert Manea
# http://dzen.geekmode.org/dwiki/doku.php?id=dzen:calendar
# modified by easysid
# Use fifo pipe to change month
FONT="dejavu sans mono"
FONTSIZE="10"
PAD=' '
ACT='onstart=uncollapse;button1=exit;button3=exit'
# Colors
FG="#a0a0a0"
BG="#202020"
highlight="#ffffff"
highlight2="#3f3f3f"
WIDTH=150
LINES=8
XPOS=1194
YPOS=30
# define pipe
PIPE=/tmp/calendar_pipe
TODAY=$(expr `date +'%d'` + 0)
MONTH=$(date +'%m')
YEAR=$(date +'%Y')
MM=${1:-"$MONTH"}
YY=${2:-"$YEAR"}
NEXT=$((MM+1))
PREV=$((MM-1))
let Y_NEXT=Y_PREV=YY
if [[ $NEXT -eq 13 ]]; then
NEXT=1
Y_NEXT=$((YY+1))
fi
if [[ $PREV -eq 0 ]]; then
PREV=12
Y_PREV=$((YY-1))
fi
# generate calender
if [[ "$MM" -eq "$MONTH" ]] && [[ "$YY" -eq "$YEAR" ]]; then # current month, highlight header and date
CAL=$(cal | sed -re "s/^(.*[A-Za-z][A-Za-z]*.*)$/^fg($highlight)\1^fg()/;s/(^|[ ])($TODAY)($|[ ])/\1^bg($highlight2)^fg($highlight)\2^fg()^bg()\3/")
else # another month, just highlight header
CAL=$(cal "$MM" "$YY" | sed -re "s/^(.*[A-Za-z][A-Za-z]*.*)$/^fg($highlight)\1^fg()/")
fi
# read from pipe
if [ ! -e "$PIPE" ]; then
mkfifo "$PIPE"
( dzen2 -u -bg $BG -fg $FG -fn "${FONT}:pixelsize=${FONTSIZE}" -x $XPOS -y $YPOS -w $WIDTH -l $LINES -sa 'c' -e "$ACT" -title-name 'popup_calendar' < "$PIPE"
rm -f "$PIPE") &
fi
# feed the pipe
(
echo "$CAL"
echo "^ca(1, $0 $PREV $Y_PREV)<<Prev^ca() ^ca(1, $0 $NEXT $Y_NEXT)Next>>^ca()"
sleep 10s
) > "$PIPE"
http://projects.haskell.org/xmobar/#other-plugins
Below is a working example where clickable workspaces are implemented.
xmonad.hs
import XMonad
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Util.Run(spawnPipe)
import XMonad.Util.EZConfig(additionalKeys)
import System.IO
myManageHook = composeAll
[ className =? "Gimp" --> doFloat
, className =? "rdesktop" --> doFloat
]
xmobarEscape = concatMap doubleLts
where doubleLts '<' = "<<"
doubleLts x = [x]
myWorkspaces :: [String]
myWorkspaces = clickable . (map xmobarEscape) $ ["1","2","3","4","5"]
where
clickable l = [ "<action=xdotool key alt+" ++ show (n) ++ ">" ++ ws ++ "</action>" |
(i,ws) <- zip [1..5] l,
let n = i ]
main = do
xmproc <- spawnPipe "xmobar /home/regj/.xmobarrc"
xmonad $ defaultConfig
{ manageHook = manageDocks <+> myManageHook -- make sure to include myManageHook definition from above
<+> manageHook defaultConfig
, layoutHook = avoidStruts $ layoutHook defaultConfig
, workspaces = myWorkspaces
, logHook = dynamicLogWithPP xmobarPP
{ ppOutput = hPutStrLn xmproc
, ppCurrent = xmobarColor "yellow" "" . wrap "[" "]"
, ppHiddenNoWindows = xmobarColor "grey" ""
, ppTitle = xmobarColor "green" "" . shorten 40
, ppVisible = wrap "(" ")"
, ppUrgent = xmobarColor "red" "yellow"
}
, modMask = mod1Mask -- Rebind Mod to the Alt key
} `additionalKeys`
[ ((mod1Mask, xK_f), spawn "firefox")
, ((mod1Mask, xK_Print), spawn "/home/regj/bin/scrotter")
, ((mod1Mask, xK_Return), spawn "urxvt")
]
xmobarrc:
Config { font = "xft:Dina:pixelsize=13"
, bgColor = "black"
, fgColor = "grey"
, position = TopW L 100
, lowerOnStart = True
, commands = [ Run Cpu ["-L","3","-H","50","--normal","green","--high","red"] 10
, Run Memory ["-t","Mem: <usedratio>%"] 10
, Run Swap [] 10
, Run Date "%a %b %_d %H:%M" "date" 10
, Run UnsafeStdinReader
]
, sepChar = "%"
, alignSep = "}{"
, template = "%UnsafeStdinReader% }{ %cpu% | %memory% * %swap% <fc=#ee9a00>%date%</fc>"
}
Extra tidbits and reference found here: www.arch-ed.dk/xmobar-clickable-workspaces/
]]>especially the in-text-formating is not in the wiki (yet), but in this readme.
]]>I have a question about xmobar and Network command:
Run DynNetwork ["-t", "<rx>|<tx>KB", "--High", "800", "-h", "red" ] 10
Is there a way to have 2 different high threshold values for reception and transmission rate?
My reception rate is significantly lower than my transmission rate, my reception rate will never reach the high threshold.
If I lower the high threshold so my reception rate can reach it, then my transmission rate will exceed it too easily...
Is there a solution for this? Or does this work different?
[edit] nvm I keep it green if > 0 like so:
Run DynNetwork ["-t", "<rx>|<tx>KB", "--Low", "0", "-n", "green" ] 10
new feature in dzen2:
- clickable areas support in the slave window
fixes:
- fixed a clickable area bug
- flush on print command
Thanks to TheUnknownCylon and Alexander Sulfrian for submitting those.
You can find the latest code on Github: http://github.com/robm/dzen
Have fun, Rob.
]]>r4 wrote:If anyone is interested, I'll post how I have dzen integrated with xmonad + the other two dzen bash scripts that launch the mail/calendar popups.
I am
Haven't checked this thread in awhile. I'm assuming you're the guy who msged me on IRC not too long ago.
When my semester ends, I'll replace this post with all the goodies. I have found a few bugs since my original post. Hopefully I can fix them too.
]]>If anyone is interested, I'll post how I have dzen integrated with xmonad + the other two dzen bash scripts that launch the mail/calendar popups.
I am
]]>