Categories
bash

latex -> text

$ catdvi -e 1 -U file.dvi | sed -re “s/\[U\+2022\]/*/g” | sed -re “s/([^^[:space:]])\s+/\1 /g” > file.txt

from

this link

More details from the original poster:

The -e 1 option to catdvi tells it to output ASCII. If you use 0 instead of 1, it will output Unicode. Unicode will include all the special characters like bullets, emdashes, and Greek letters. It also include ligatures for some letter combinations like “fi” and “fl.” You may not like that. So, use -e 1 instead. Use the -U option to tell it to print out the unicode value for unknown characters so that you can easily find and replace them.

The second part of the command finds the string [U+2022] which is used to designate bullet characters (•) and replaces them with an asterisk (*).

The third part eats up all the extra whitespace catdvi threw in to make the text full-justified while preserving spaces at the start of lines (indentation).

After running these commands, you would be wise to search the .txt file for the string [U+ to make sure no Unicode characters that can’t be mapped to ASCII were left behind and fix them.

Categories
bash debian

debian-multimedia GPG error

well I’ll see if this fixes the error that’s been breaking my nightly cron-apt.

[sourcecode lang=”bash”]
sudo su
gpg –keyserver hkp://pgpkeys.mit.edu –recv-keys 07DC563D1F41B907
gpg –armor –export 07DC563D1F41B907 | apt-key add –
[/sourcecode]

it doesn’t work. now just tried:

[sourcecode lang=”bash”]
sudo aptitude install debian-multimedia-keyring
[/sourcecode]

if that works its definitely superior.

Categories
bash debian

How to keep less from clearing the screen

I was finally getting desperate with R’s history() command clearing my screen after showing me my history, totally useless. After some puttering around, i found that history() just ends up calling $PAGER, which for me was less. Typing h into history() confirmed that I was looking at less. So then googling how to get rid of less’s behaviour turned up this page:

http://www.shallowsky.com/linux/noaltscreen.html

which gave the magic key as

export LESS=”-X”

in .bashrc. this prevents less from opening an “alternate” screen when it runs. helps with manpages also. i don’t know who or why anyone came up with this alternate screen nonsense.

Categories
bash samba

smbclient, beamer, and pgfpages

Today’s problem is that I need to print slides for a poster session that I’m going to. I’ve never printed to the color printer, so I don’t know the share name. Simple:

[sourcecode lang=”bash”]
smbclient -L server.com
[/sourcecode]

prints all the shares from that server, so then I can just grep the output since I have an idea how the admins name the printers (based on room number, floor, and printer model). I found the share name and made a little shell script that prints to the share. I also found that there’s a number of commands one can send through smbclient to the server and share, such as:

[sourcecode lang=”bash”]
smbclient -d3 //server.com/printershare -A authfile -c "queue"
[/sourcecode]

and even

[sourcecode lang=”bash”]
smbclient -d3 //server.com/printershare -A authfile -c "help queue"
[/sourcecode]

for example. Then there’s “cancel”. However on my particular setup, I didn’t see any print jobs listed when I gave the “queue” command even though I knew there was one queued up. Maybe it’d been sent to some 3rd intermediate machine, or maybe it was already in the printer’s memory.

Next, I needed to get my beamer slides printed to the color printer. I printed them, and it turns out they’re shrunk down for no reason (but they’re color, so that’s good). I need them normal size to paste onto the poster board. To do that, I found the beamer manual giving an example using pgfpages (which had a few typos and again used a4paper which is a nuisance since I’m in the USA). Had to investigate pgfpages.sty (since pgfpages has no documentation, surprise). The correct command to get pgfpages to print on my system this time was:

[sourcecode lang=”tex”]
\usepackage{pgfpages}
\pgfpagesuselayout{resize to}[letterpaper, landscape, shrink=5mm]
[/sourcecode]

For a while my problem was using curly rather than square brackets for the 3 parameters. Now the problem is that the color laserjet 2500L just prints pages of junk rather than the slides. In the process of dealing with that I found that I could “login” to the print share by doing

[sourcecode lang=”bash”]
smbclient -d3 //server.com/printershare -A authfile
[/sourcecode]

and then issue commands like “cancel 1” and “cancel 100” directly. They all succeed, but I never get to actually see the queue.

Finally the other struggle with this morning and afternoon has been with the HP Color Laserjet 2500L itself. Downloading the manual is essential, since the printer has nothing but hieroglyphics on its panel. I don’t know why people think that a red button with a triangle automatically means cancel print job. In any case, reading the manual is essential, since a button was flashing with some hieroglyphic next to it, and I discovered this meant paper jam, which gave me the impetus to actually pull out the toner cartridge (which I’d never done, I don’t maintain this printer) and then find the paper and replace the cartridge. And somehow, now, my slides are actually printing in color.

I think one important thing is to do dvips to get the postscript output rather than making a PDF file and converting to PS using pdf2ps. The file seems alot smaller. It is very slowly printing right now, which suggests to me that one of the older jobs where I did pdf2ps is printing, instead of my latest jobs using dvips.

Categories
bash debian vim

beeps

i hate beeps of all kinds. the new install was beeping when gdm started, then it was beeping for no reason when i hit capslock in the empty space, when man pages over the beginning or end of a manpage, etc. i needed this fixed. found a few things on the internet, but i feel my solution so far is incomplete:

add to /etc/modprobe.d/blacklist
blacklist pcspkr

add to .xinitrc
xset b off
xset b 0 0 0

add to .inputrc (this i knew already)
set bell-style visible

add to .bashrc
set visualbell
export PAGER=less
export LESS=”-Q”

add to .vimperatorrc
set visualbell

Categories
bash debian Uncategorized

smbclient

I run on a Debian machine, and I’m in a Windows environment. So from time to time I have to map some share on a machine and upload or download some file. Every time I panic because I don’t remember how to do this smbclient stuff, so I’m just going to post it here. First, I have a file called authfile, which has in it 3 lines:
[sourcecode]
username = myusername
password = mypassword
domain = thedomain
[/sourcecode]

Then say we have a server MX20 and a “share” called “Shared”, then all I have to do is

[sourcecode lang=”bash”]
smbclient //MX20/Shared -A authfile
[/sourcecode]

This logs me in, and then I can drill down to whatever folder they want and get and put the required files.

Categories
bash debian git Uncategorized vim

cryptsetup and quickfix

2 unrelated things which I fixed up today. First, a few days ago my Fujitsu P7320, which I am very fond of, had its HD fail. So it’s off being repaired, presumably returning with a fresh HD. I used it often to transfer files between my various machines using git – although git is a dvcs, i was also using it to sync machines, leading to lots of illogical commits, which I’m sure some purist would say is appalling, but it works and works fast, and so far I haven’t had trouble. But now that the Fujitsu is out, I needed to use a thumbdrive. Last time I used one for syncing, i lost it for some time, then weeks later found when the snow in my driveway melted. (Amazingly, it still worked.) But while it was lost I was always worried about whether there were any important passwords cc’s etc on the drive. I determined to never use an unencrypted thumbdrive again. So today I had to get it encrypted in a hurry, and I found the relevant commands and they were simple, so here they are:
[sourcecode lang=”bash”]
cryptsetup luksFormat /dev/sdX
cryptsetup luksOpen /dev/sdX thumbdrive
# enter password
mkfs.ext2 /dev/mapper/thumbdrive
mount /dev/mapper/thumbdrive /media/thumbdrive
# do whatever
[/sourcecode]

Much easier than I was expecting.

The second thing I rediscovered was quickfix on vim with g++. I was doing some simple editing of a single C++ file, and I wanted quickfix working again but I forgot everything. Here’s the lines from the .vimrc that make it go:

[sourcecode lang=”vim”]
set errorformat=%f:%l:\ %m,In\ file\ included\ from\ %f:%l:,\^I\^Ifrom\ %f:%l%m
set makeprg=g++\ -Wall\ -pedantic\ %\ -lm\ -lgsl\ -lgslcblas\ -o\ %<
[/sourcecode]

That’s it. obviously later when using a makefile for real, I’ll have to modify the makeprg and make it.. just make.. but this works quick and dirty.

Categories
bash git

bash scripts for using git to sync laptops

I have 3 Debian laptops which I use daily. One at home, one at school, and one which I carry in my backpack. I’m also a backup nut. I have 4 external drives totaling 3.25T of storage which are for storing and backing each other up. For years I used rsync with linked files, which was alright but always had issues — sometimes the links wouldn’t propagate back properly for no apparent reason. I’d have the impression that things were working well when … really there was just the latest snapshot available.

Recently I’ve switched to unison for backing up things like photos and videos, which works great and has a nice GUI. It makes snapshots and just synchronizes the drives, with minimal muss and fuss.

But for my daily work, I want something with some history, like I had hoped to get from rsync, so I can revert a file to its previous state. I wanted something which wouldn’t have a ‘main’ copy and then child copies but rather where each laptop could function stand-alone and then quickly synchronize with the others whenever they were available. I wanted something which could run over ssh. I suspected git might do some of it, but I am surprised now how much of what I wanted, git does, and does well.

So I tried out git for while, but git has a steep learning curve. So steep that its the kind of thing which I abandon if I don’t get traction quickly, since I have little time to learn technical tools like this, especially tools which are not documented for beginners. (I’ve had that issue with OpenBSD, which seems like a nice OS, and which I’ve installed, but I’ve run into issues within the first day and then had to reformat over with Debian testing.)

However git has something which is an absolutely remarkable solution to this problem. There is an excellent, friendly git IRC channel at irc.freenode.net/#git. Several people there have given me such valuable advice specific to my situations that came up in the beginning that I’ve learned git to the point where it’s a tool that helps me so much I can’t do without it. There’s lots of primers and introductions out there, but I didn’t find one that really cut it for me; it is sorely needed, but the IRC channel makes up for its absence.

One key piece of advice I got was to avoid git push and pull in the beginning, and rather use git fetch and merge only. This was good advice, since you get a better sense of what each piece is doing, and it works.

So I wrote a couple of bash scripts which I use everyday and which I like. First I have in my .bashrc a line like

export GITDIRS=~/proj1:~/proj2:~/proj3

Whenever I need to sync up laptops I run the following bash script I call gitac (for git-add commit):

#!/bin/bash

IFS=: 
for gitdir in $GITDIRS; do 
    echo $gitdir 
    pushd $gitdir 
    git add .  
    git commit 
    popd 
done

and then I ssh to the target laptop and run gitfr (for gitfrom):

#!/bin/bash

IFS=: 

for gitdir in $GITDIRS; do
    echo $gitdir 
    pushd $gitdir 
    git fetch $1:$gitdir HEAD 
    git merge FETCH_HEAD 
    popd 
done

These work superfast and sync my laptops better than I could’ve asked for from rsync. I can see the commits graphically using gitk which is nice.

When I’m syncing my laptops it isn’t always a sensible time to do a significant commit on all my projects, but with git you can have several branches, one for daily working commits and another for significant commits — I’ve yet to completely work that out and also find out how to propagate such branch information. git is flexible about how you use it, and if it works, then it works. Another thing I like is that none of the machines is “central”; in fact, I view them all as backing each other up. In particular, I don’t need the external drives for backing up my daily work anymore, they’re only for photos, videos, and things like that.

The only obvious issue is if I edit the same file on 2 different laptops and then sync, then I get merge conflicts, as would be expected. At first this was a problem, but now I generally remember to start a work session by gitfr from my backpack laptop to keep everything sync’d up.

Categories
bash

bash completion for vim and latex

I want bash to complete .tex whenever I type vim file. and there’s a file.tex in the directory. This was driving me nuts since it was completing all the LaTeX aux files etc whenever I did it, but I found (again) /etc/bash_completion which has the line

complete -f -X ‘*.@(o|so|so.!(conf)|a|rpm|gif|GIF|jp?(e)g|JP?(E)G|mp3|MP3|mp?(e)g|MPG|avi|AVI|asf|ASF|ogg|OGG|class|CLASS)’ vi vim gvim rvim view rview rgvim rgview gview

which is obviously the line in question. all i did was add (aux|out|log to these filetypes and put that line in my bashrc and its working much better. frankly this was just lucky, since i dont think more than about 50-200 people in the world really understand bash completion very well.

there’s an incredible programmer i came across who wrote something interesting called compleat.

also i rediscovered FIGNORE, which is a list of file extensions for bash to ignore on all completions. just export it from your .bashrc.