arpa: (Ar)ch (pa)ckages – generic package tasks wrapper script

Todd Partridge (Gently):

Arch wrapper for pacman updated, very well tuned now.

Originally posted on Linux Tidbits:

I once saw a wrapper-script for pacman in the forums that was basically a short-hand version of common pacman tasks. Over the last couple years, I’ve expanded on it. It does just about everything I need it to and its real basic. I call it arpa and here are the tasks it covers:

arpa [option] [*package] - generic package tasks wrapper script -e, --explicit - install a package as explicit -g, --get - only download package files : -G for upgrade files -i, --install - install a package : -I for deps, *.pkg.tar.* -l, --list - list files installed by a package : -L genlist inst. pkgs -n, --info - information about a package -o, --owns - owning package of a file -q, --query - query for an installed package : -Q adds description -r, --remove - remove a pkg and its deps : -R force, no param orphs -s…

View original 43 more words

bashrc

Todd Partridge (Gently):

Updated today, gotten better… redone.

Originally posted on Linux Tidbits:

The ~/.bashrc is a the bash shells’ setting file. The ~/.bashrc can also be used to specify other bash shell related items like abbreviating commands and creating shortcuts. Here is my ~/.bashrc , all bells, no whistles.

View original

Get down with getopt

What is getopt?

getopt is a command used in scripts to parse their options and add a basic error checking ability. getopt is not getopts the bash built-in that has similiar functionality. Urban Vagabond explains:

getopt and getopts are different beasts, and people seem to have a bit of misunderstanding of what they do. getopts is a built-in command to bash [that] processes command-line options in a loop and assigns each found option and value in turn to built-in variables [(so that they can be further processed)]. getopt, however, is an external utility program, and it doesn’t actually process your options for you the way that [(e.g.)] bash getopts, the Perl Getopt module, or the Python optparse/argparse modules do. All that getopt does is canonicalize the options that are passed in — (i.e. convert them to a more standard form) so that it’s easier for a shell script to process them.

For example, a use of getopt converts the following:

tmpscript -abd -ooutfile.txt

into this:

tmpscript -a -b -d -o outfile.txt

getopt can also process the long format option of --output=/tmp.... Also basic error check abilities, it has:

tmpscript -c
tmpscript: invalid option -- 'c'

or

tmpscript -o
tmpscript: option requires and argument -- 'o'

getopt gets defined by telling it the available options in short and long form (if you like). An option with a colon (:) following denotes that an argument is required for that option. If followed by two colons the argument is optional. Here is an example:

Options are generally set as variables so that they can defined how to be used after the while loop (usually, so that mainly they are processed in the right order). getopt parses in the same order as specified on the input, so a -a -d -b input would not work real well if the -d option required the -b option to run correctly.

One caveat of getopt is that each option allows either one or no arguments to follow. So in input like tmpscript -v --files file1.txt file2.txt file3.txt just isn’t possible in any type of predictable-fashion. One can however use quotes on the input:

tmpscript -v --files "file1.txt file2.txt"

or use mutiple options (-f file1.txt -f file2.txt) and append them to an array, as seen, here.

Lg monitor ips224v-pn, look

I decided to get the LS IPS224V-PN and here is a look at it. First thing I noticed was that the stand was a bit… rickety, probably from the thin neck. This does get noticed especially with the desktop I own, tetters. The second thing I noticed was how even the picture was: good, crisp, even, vibrant. The other thing I noticed was the permeating, yellow din that I’m familiar with with LEDs. This last thing can fortunately be adjusted).

Details Value
Contrast ratio 5,000,000:1
Resolution 1920×1080
Response time 14ms
Input D-Sub, DVI, HDMI
Output Headphone
IPS Yes

I’m not sure what ips is but I think it contributes to the nice viewing angle.

Setup was real easy, took no more than a few minutes and monitor calibration was basic.

Setting Default New
Brightness 100
Contrast 50 71
Color Temp Custom Cool

The color temperature of cool does a good job to neutralize the yellow color the LED; however the custom setting did better with pictures.

Alternate (yellow LED color remains):

Setting Default Alt.
Brightness 100
Contrast 50 67
Color Temp Custom
Red 50 46
Green 50 46
Blue 50 59

Ultimately I choose to use the cool temperature.

The power button is a large half-circle with an refracting light to indicate power-saving. However, it is extremely bright. There is an option to turn it off when the power is off, but it will still be seen in standby-mode; I’ve had to cover mine up.

I got this display for reading and it is good for that. Text looks very nice. But it also is good with pictures at least as far as my semi-professional eye is concerned. The 14ms (WTG?) response time is a bit on the high end. Videos do show a bit of “ghosting” but it doesn’t bother me that bad.

Numbered file backups – Easy as can beasy

file-twoWhen I’m about to edit a configuration file or a bash script, sometimes I don’t know if the edit will work. In these cases I create a backup of it in numbered order (to keep track of them if I need to revert the changes). Because this is something I regularly do, I decided to build a script to make this easy. The usage is basic: define the file and destination-directory:

# bckfile definedfile.bash .
‘/home/johndoe/.local/bin/definedfile.bash’ -> ‘/home/johndoe/.local/bin/definedfile_00.bash’

Optionally a tag can be added too:

bckfile youdle .vault/ new
‘/home/johndoe/.local/bin/youdle’ -> ‘/home/johndoe/.local/bin/youdle_02-new’

A limitation of the script is that filename cannot have ‘periods’ in their filename. A heuristics of discovering multiple extensions and with . in the filename itself would be tough.

gt – script to create a temp file in gedit

posticon

I am really lazy with my editors. I have aliases in my shell configuration for gedit and vim that are very basic:

alias v="vim -p" # open in tab
alias sv="sudo vim -p"
alias g="bgcmd gedit"
alias sg="bgcmd gksudo gedit"

This is very nice for me because I use my editors quite a bit. One thing I needed though was a command that would create and open a temporary file in gedit. The main reason for this is that at the time I don’t know how to name or place the file properly. Another reason is that at other times I like to have a scratchpad but would lose information if it was just a New File and a crash… happened.

Running just gt will create and open a file named of the current time (MMDDhhmm) and will be saved in the trash folder. If gt is followed by a name (e.g. gt cssbox or cssbox.css) the name will be appended to the current time.

Screenshot from 2013-08-26 08:17:12

The name is helpful if wanting to dig the file out of the trash folder at a later time.

WTFM (Write the Fine Manual) with Pod2man text-converter

Note: This is a guide from a lightly-proficient manual writer that’s targeted for beginning users: it’s formatting method is easy and conversion method is basic. This method may also be helpful for those that use github because it has rendering support for this method. For a more traditional approach, nixCraft has an article for that.

Because it was the authors first effort to write a man page, talk was that it was good to use Pod2Man. Pod2man is an application that converts text using Plain Old Document (POD) formatting to traditional manual (man) pages. POD markup is easy to do and pod2man is conveniently pre-installed on most Linux distributions (as it is part of the Perl package).

An example

To get a good idea of what to do, here is a basic example demonstrating the formatting (of a fictitious program dr-smile):


=encoding UTF8

=head1 NAME

dr-smile - output platitudes to help to improve one's mood

=head1 SYNOPSIS

dr-smile [B<--happy>] [B<--joke>=F<type>]

=head1 DESCRIPTION

B<dr-smile> outputs jokes and happy thoughts designed to make one fell F<--better>.  It has the ability to output pleasant thoughts, jokes, good memories, optimistic fortunes...  B<dr-smile> I<isn't> a replacement for a professional doctor, please use responsibly and enjoy.  Additional options are available in the configuration file F</etc/dr-smile.conf>.

=over 4

=item B<-h>B<--happy>

A general happy thought will be output (e.g. C<dr-smile --happy>).

=item B<-j> F<type>B<--joke>=F<type>

A good-sense joke will be told.  The types are: F<knock> and F<oddball>.  Read more in B<jokes(1)>.

=back

Formatting

There is both text formatting and section formatting that is required for a man page.

Text formatting

All the POD text formatting tags needed to know are as follows:

Bold B<text>
Italic I<text>
Link L<http://address.org >
Filename F<file>
email E<gt>name@address.comE<lt>

Man pages use two types of formatting (that I’ve ever seen). That are implemented by POD’s bold formatting and PODS filename-or-italic formatting:

Formatting type Used for
POD Bold formatting
  • Program names
  • Options
  • Manuals
POD Filename formatting
POD Italic formatting
  • Files
  • Keywords
  • Emphasis
  • Arguments
  • Occasionally manuals

Section formatting

There are three section tags that are used in pod2man (that I know of). The pod2man manual refers to these as Command Paragraphs and they are: header/category sections, item sub-sections, and “over” sub-sub-sections for additional descriptions of item sections. References to all of these are in the above example.

  • Header/Category sections are the block descriptors and their contents (like NAME, and DESCRIPTION…).
  • Item sections refer to options generally and often override =over sections for their list item.
  • Over sections refer to option descriptions.

General layout structure

Man pages follow a basic (though liberal) structure can be well represented by this:

NAME
The name of the command, followed by a one-line description of what it does.
SYNOPSIS
A representative invocation of how to run the command and options it has.
DESCRIPTION
A detailed description of the functioning of the command.
OPTIONS
A list of it's options (these are sometimes put in DESCRIPTION).
EXAMPLES
Some examples of common usage.
BUGS
List known bugs.
SEE ALSO
A list of referenced or related commands.
AUTHOR
   Specifying the contact information.
COPYRIGHT
   Specifying the copyright information.

The order of categories varies a bit from man page to man page. The first four categories are almost always the same, however the remaining vary a bit. The above layout is an mnemonic aggregate of category order of the man pages that the author has seen.

Convert pod format to manual page

Pod2man usage is basic:

pod2man dr-smile.pod > dr-smile.1

However, these additional options will probably be wanted to be added, plus compression:

pod2man --section=1 --center="dr-smile manual" --name="dr-smile" --release="1.0" dr-smile.pod | gzip > dr-smile.1.gz

Result

screenshot-manpage

Resources

Follow

Get every new post delivered to your Inbox.

Join 52 other followers