Shallow Thoughts : tags : tip
Akkana's Musings on Open Source Computing and Technology, Science, and Nature.
Mon, 04 Mar 2013
My Lenovo laptop has a nifty button, Fn-F5, to toggle wi-fi and bluetooth
on and off. Works fine, and the indicator lights (of which the Lenovo
has many -- it's quite nice that way) obligingly go off or on.
But when I suspend and resume, the settings aren't remembered.
The machine always comes up with wireless active, even if it wasn't
before suspending.
Since wireless can be a drain on battery life, as well as a potential
security issue, I don't want it on when I'm not actually using it.
So I wanted a way to turn it off programmatically.
The answer, it turns out, is rfkill.
$ rfkill list
0: tpacpi_bluetooth_sw: Bluetooth
Soft blocked: yes
Hard blocked: no
0: phy0: Wireless LAN
Soft blocked: yes
Hard blocked: no
tells you what hardware is currently enabled or disabled.
To toggle something off,
$ rfkill block bluetooth
$ rfkill block wifi
Type rfkill -h
for more details on arguments you can use.
Fn-F5 still works to enable or disable them together.
I think this is being controlled by /etc/acpi/ibm-wireless.sh,
though I can't find where it's tied to Fn-F5.
You can make it automatic by creating /etc/pm/sleep.d/.
(That's on Ubuntu; of course, the exact file location may vary with distro
and version.) To disable wireless on resume, do this:
#! /bin/sh
case "$1" in
resume)
rfkill block bluetooth
rfkill block wifi
;;
esac
exit $?
Of course, you can also tie that into other things, like your current
network scheme, or what wireless networks are visible (which you can
get with iwlist wlan0 scan
).
Tags: linux, ubuntu, laptop, tip
[
19:46 Mar 04, 2013
More linux/laptop |
permalink to this entry |
]
Sun, 11 Dec 2011
Need your Ubuntu clock to stay in sync with a dual-boot Windows install?
It seems to have changed over the years, and google wasn't finding any
pages for me offering suggestions that still worked.
Turns out, in Ubuntu Oneiric Ocelot,
it's controlled by the file /etc/default/rcS: set
UTC=no
.
Apparently it's also possible to get Windows to understand a
UTC
system clock using a registry tweak.
Ironically, that page, which I found by searching for
windows system clock utc
, also has the answer for setting
Ubuntu to local time. So if I'd searched for Windows in the first
place, I wouldn't have had to puzzle out the Ubuntu solution myself.
Go figure!
Tags: linux, ubuntu, tip
[
13:56 Dec 11, 2011
More linux |
permalink to this entry |
]
Wed, 25 May 2011
Most of the time when I edit a text file in vim, I want lines to wrap
automatically as I type, at somewhere around 70 columns wide.
So I set textwidth=70
in .vimrc.
But sometimes that isn't appropriate. For instance, I have a procmail
rules file where I put common spam patterns that programs like
spamassassin don't seem to be able to catch. So I might have lines like:
*^Subject:.*(Ink Cartridges|Hummingbird Vine|who's who of executives|Avandia|Botox|Your Email ID|Zoosk|Best airfares on the internet|UGG Boots|police training)
... and so on -- you get the idea. I can't have lines breaking in the
middle, because then the procmail rule wouldn't work. So every time I
add a new phrase, I have to
:set tw=0
(or one of the other
umpteen ways one can tell vim not to wrap lines) first.
But you can set special behavior for one specific file by adding a
special comment called a "modeline" as the first line of the file.
Procmail treats any line starting with a hash, #, as a comment,
and vim recognizes # as a comment.
So I can add this as the first line of the procmail file:
# vim: set tw=0:
then vim will see that and un-set that default text width I specify
in .vimrc.
Vim understands most common comment styles, so it should understand lines like
/* vim: set tw=0: */
and // vim: set tw=0:
and ; vim: set tw=0:
as well.
But to make this work I had to do one more thing: in .vimrc, I had to add
set modeline
Apparently on some versions of vim this is on by default; in others
it's turned off for security
reasons (someone could put an evil modeline into a file which
would make your vim do something when you edited it).
Definitely something to be aware of, but if you mostly edit files
you created yourself on your local machine, and no one else uses your
machine, it's your choice whether to worry about it.
Emacs has modelines too
Emacs has mode lines too, though it calls them
Local
variables lines.
For instance, C++ files in Mozilla's source tend to start with:
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
It's awfully handy to be able to define specific indentation style for the
files within a project, making it easy for emacs users, at least, to
follow your preferred coding style. If only all editors understood them!
Tags: editors, vim, emacs, tip
[
21:26 May 25, 2011
More linux/editors |
permalink to this entry |
]
Mon, 14 Feb 2011
As most veteran IRC users know, IRC commands generally start with a
slash at the beginning of a line. For instance, you say
/join #channel
to join a new channel, or
/me waves to everyone
to send "*akk waves to everyone" to the channel.
Great, but what if I want to start a line with a slash?
On some IRC clients, you can type two slashes, e.g.
/ /me tries
but on xchat that doesn't work -- it just complains "unknown command".
On xchat, what you need is /say:
/say /me succeeds!
Silly little tip, but I know I'll forget it if I don't record it ...
and I bet I'm not the only xchat user wondering how to do this.
Update: it turns out that sometimes in xchat you can use a double slash
with no spaces:
//me tries
which is the obvious thing to try, but it hasn't always worked
reliably for me. Try it ... but you can fall back on /say
if // doesn't work.
Tags: irc, xchat, tip
[
21:55 Feb 14, 2011
More linux |
permalink to this entry |
]
Fri, 04 Feb 2011
For some time I've been mildly annoyed that whenever I start emacs
and open a file that's under any sort of version control -- cvs,
svn, git or whatever -- I can't start editing right away, because
emacs has to pause for a while and load a bunch of version-control
cruft I never use. Sometimes it also causes problems later,
when I try to write to the file or if I update the directory.
It wasn't obvious what keywords to search for, but I finally found
a combination, emacs prevent OR disable autoload vc
(the vc was the important part), which led me to the
solution (found on
this page):
;; Disable all version control
(setq vc-handled-backends nil)
Files load much faster now!
Tags: editors, emacs, git, tip
[
13:11 Feb 04, 2011
More linux/editors |
permalink to this entry |
]