Re: Post your handy self made command line utilities

I wrote a script to create new files based on my custom templates, so that I just have to type "new html index.htm", for example. The original was in bash, but I recently redid it in Perl to add more functionality (and I'm much more familiar with Perl than bash).

Usage: new FILETYPE [FILENAME] [-- optional arguments]

The first argument is mandatory and is one of the files in the template folder (~/Dropbox/templates). The 2nd argument is an optional name for the new file; if it's not given, then the filename will be taken from a directive in the template file; if that doesn't exist, the filename of the template will be used.

The script looks for the strings '#DATE#', '#PROJECT#', '#FILENAME#', '#UC_FILENAME#', and '#ARGS#', and replaces them with, respectively, the date and time, the current working directory, the filename, the filename in uppercase (I use this in my template for C header files), and optional arguments that can be anything, really.

If the file starts with this:

# default filename: main.c
# --

the script uses that filename to create the new file, and strips those first 2 lines from the new fil.

Re: Post your handy self made command line utilities

Back before I had heard of rlwrap, I wrote the following simple shell function for having a readline input line with programs that do not support that natively:

rline () {
socat READLINE EXEC:"$*",pty
}

Its usage is simply "rline <program>". Socat takes input via the readline library and passes it to the stdin of the given program. The ",pty" option makes it simulate a pseudo-TTY for programs that don't want to read from pipes. I still use this wrapper function because I have known it to work when rlwrap didn't. On the downside, it does not treat passwords specially, i.e. displays them in plain text. Also, the input text is echo'd when it is passed to the program.

Re: Post your handy self made command line utilities

I started doing pull-ups about a year ago. I was in the worst shape of my life, always sitting infront of a computer both at home and at work and decided that my belly had to go. Initially I could not even do one proper pull-up but I kept doing them at least 3 times per week and now I am up to 10 in a row and have lost 12kg's.

I wrote this script based on "Pavel's Ladder Pull-ups" to keep myself going forward. I really recommend this excercise to all you archers/geeks/nerds/hackers that spend too much time infront of your computers and no time exercising. Pull-ups is the ultimate upper body exercise and can get you ripped with just 3 times/week * 15min, so having little time is no excuse. Consistency is the key!

Re: Post your handy self made command line utilities

Wasn't good at trying to remember my pacman aliases in zsh so I wrote this function in my zshrc for most cases which just makes all the common pacman actions a shorthand style command where it can be typed with "pac" followed by any command arguments without "-" (caps don't matter in the first positional parameter, it converts the initial letter to uppercase anyways). It should work in bash as well.). No need for error handling when pacman can do that. Simple and eliminated my long list of unused aliases... It was lot easier to remember just "pac" and any arguments i wanted to pass to it....."pac syu", "pac Syu", "pac u package.tar.xz" and "pac s package" will all translate to their appropriate commands. It works for all actions I use, long ones as well under most conditions (if they're really complex they probably need to be typed out normally...)

"You are like people in a dark room waiting for someone to turn the light on for you instead of groping around in the dark and turning it on for yourself." -J. Krishnamurti at age 19, to his students-www.jkrishnamurti.org

Re: Post your handy self made command line utilities

I edited it to use cpupower and to use a static temperature (you have to give it your actual min cpu frequency in the cpupower line):

So the original is not mine but figured I'd share my version with you guys anyways.

I like this. I wrote a script a long time ago using zenity to manually change CPU freq on the fly, but this is better. However, none of the temperature reading lines works here. The following does, using sensors:

Re: Post your handy self made command line utilities

I know, it's ugly. It found the way to life last night, when I was frustrated about the fact, that I cannot automatically add feeds from firefox to newsbeuter. Call me stupid, but I forgot how to use sed to change some lines in a file and write it back to that file, hence the ugly tempfile approach. Did I forget how to do my job over night, or does sed not accept simple text input? Do I really have to echo $1 | sed...?

*doing some research and experiments*

#!/bin/bash
sed "s/feed:/http:/g" <(echo "$1") >> ~/.newsbeuter/urls

Yeah, ok. Looks better.

Cownose, the cat: You can have firefox give the feed-URI to the script and it will append it to the newsbeuter urls file. It will also replace the ugly "feed://" by a nice "http://".

Re: Post your handy self made command line utilities

I got bored and made a password-generator in bash. Not the first to do so, but it has support for different ascii classes, statistics and can make a password based on required bits. Comments on how to improve my bash scripting is encouraged.

options can be viewed by issuing "-help" as argument (or looking at the script)

Re: Post your handy self made command line utilities

graph wrote:

I got bored and made a password-generator in bash. Not the first to do so, but it has support for different ascii classes, statistics and can make a password based on required bits. Comments on how to improve my bash scripting is encouraged.

Re: Post your handy self made command line utilities

I've never tracked down details on this, but \003[ has proven much more 'portable' or reliable under varied conditions than \e[. I'm guessing (just guessing at this point) that the later is an optional feature of some terminals or terminfo settings.

Unfortunately these are rather difficult terms to google for to learn more.

Re: Post your handy self made command line utilities

Trilby wrote:

I've never tracked down details on this, but \003[ has proven much more 'portable' or reliable under varied conditions than \e[. I'm guessing (just guessing at this point) that the later is an optional feature of some terminals or terminfo settings.

Unfortunately these are rather difficult terms to google for to learn more.

Re: Post your handy self made command line utilities

No. The equivalent of e (hex) in octal would be 16, or 33 (octal) un hex would be 1b. I think e just stands for "escape", but what they represent is not particularly relevant - I'm just speaking from my experience about whether or not they work - and \e[ does not work consistently (for me).