You are not logged in.

#2576 2015-06-04 04:07:57

progandy
Member
Registered: 2012-05-17
Posts: 5,263

Re: Post your handy self made command line utilities

Trilby wrote:

Thanks theodoreward, but that misses the important criteria of being able to log in from anywhere if/when needed without having anything special on the system.

There is a foolproof system that doesn't require a computer. Use the initials, numbers, and punctuation marks of your sentence. If you are missing some numbers append the current year.

June is a crazy month in 2015!

Jiacmi2015!

PS: The password manager clipperz.is only requires a browser and javascript. It claims to be secure since everything is encrypted locally. There should be some other similar webservices.

Edit: If you always have a browser + javascript, then you can use some javascript for your base64 instead of a linux emulator.

javascript:alert(btoa(prompt("Passphrase:", "June is a crazy month").replace(/\s+|$/g,"\xfe")))

Last edited by progandy (2015-06-04 06:36:55)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#2577 2015-06-04 05:58:47

Fylwind
Member
Registered: 2015-06-04
Posts: 5

Re: Post your handy self made command line utilities

Trilby wrote:
 printf "%s\xFE" $@ | base64

Maybe it would be better to use something like:

{ cat; printf "\xFE"; } | base64

so your passphrase doesn't get logged in the shell history.

Offline

#2578 2015-06-04 06:19:33

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Post your handy self made command line utilities

Fylwind wrote:
Trilby wrote:
 printf "%s\xFE" $@ | base64

Maybe it would be better to use something like:

{ cat; printf "\xFE"; } | base64

so your passphrase doesn't get logged in the shell history.

Or you could just type a space before the command...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#2579 2015-06-04 06:44:15

x33a
Forum Fellow
Registered: 2009-08-15
Posts: 4,587

Re: Post your handy self made command line utilities

@ jasonwryan, at least in my case, it still gets logged. But that is probably because I don't use the default bash settings. Here are my settings for reference.

# Increase bash history size
export HISTSIZE=5000

# append to history file, instead of overwriting it.
shopt -s histappend

# save all lines of a multiline command in same entry
shopt -s cmdhist
shopt -s lithist

# remove duplicate lines from history
export HISTCONTROL=erasedups

PROMPT_COMMAND="history -a"

Offline

#2580 2015-06-04 06:46:05

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Post your handy self made command line utilities

You need HISTCONTROL set to ignoreboth (which is the default IIRC)...

#edit: my bad, Arch's default bashrc contains no HIST settings: you'd need to explicitly set ignorespace or ignoreboth; it must be a debian thing tongue


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#2581 2015-06-04 08:37:37

x33a
Forum Fellow
Registered: 2009-08-15
Posts: 4,587

Re: Post your handy self made command line utilities

@ jason,

I can confirm that ignoreboth does lead to ignoring of commands with a preceding space.

Offline

#2582 2015-06-12 01:53:16

genEric
Member
From: Sweden
Registered: 2013-09-26
Posts: 38

Re: Post your handy self made command line utilities

x33a wrote:

@ jason,

I can confirm that ignoreboth does lead to ignoring of commands with a preceding space.

You can also specify more/other characters to be ignored with “HISTIGNORE” (somewhat useful).

Example:

export HISTIGNORE='&:[ ]*#'

# ignoreboth (= ignoredups + ignorespace)
export HISTCONTROL=ignoreboth:erasedups

Which will make a comment to be ignored.

# fooBar comment

[genEric@…] ~$

Offline

#2583 2015-06-12 07:44:01

x33a
Forum Fellow
Registered: 2009-08-15
Posts: 4,587

Re: Post your handy self made command line utilities

@ genEric, nice!

Offline

#2584 2015-06-13 05:36:34

Jakkin
Member
From: 403 Forbidden
Registered: 2014-10-16
Posts: 18

Re: Post your handy self made command line utilities

I've got one to "automate" my system updates and general maintenance. http://pastebin.com/mVM7iF57 What have you done to make your lives easier?


Anyone who NEEDS to be TAUGHT how to interact with a computer probably shouldn't be allowed near one. -Sopwith

Offline

#2585 2015-06-13 05:44:25

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,203

Re: Post your handy self made command line utilities

Merging with Post Your Handy Command Line Utilities

Last edited by ewaller (2015-06-13 05:45:10)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#2586 2015-06-13 06:16:19

grandtheftjiujitsu
Member
Registered: 2013-07-27
Posts: 91

Re: Post your handy self made command line utilities

I'm not a huge movie watcher, so until I watched one the other night I almost forgot that I had made a script to choose whether to rip / burn / play DVDs.

#!/bin/bash
# CD / DVD - Rip, Burn, Play

# Functions
menu () {
  echo -e "What would you like to do:\n
  [1] Play DVD / ISO
  [2] Create ISO from DVD
  [3] Create ISO from Directory
  [4] Burn ISO to DVD
  [5] Format and Erase CD / DVD + RW
  [6] Exit\n"
  echo -n "Selection: " && read MENU_OPT

  if [ "$MENU_OPT" == "1" ] ; then
	play
  elif [ "#MENU_OPT" == "2" ] ; then
	iso_from_dvd
  elif [ "$MENU_OPT" == "3" ] ; then
	iso_from_directory
  elif [ "$MENU_OPT" == "4" ] ; then
	burn
  elif [ "$MENU_OPT" == "5" ] ; then
	format
  else
	menu
  fi
}

play () {
  echo -n "Which would you like to play? (dvd / iso): " && read PLAY_CHOICE
  if [ "$PLAY_CHOICE" == "dvd" ] ; then
	mpv dvd:// --dvd-device=/dev/sr0	
  elif [ "$PLAY_CHOICE" == "iso" ] ; then
	echo -n "Enter /path/to/image.iso: " && read ISO_LOC
	mpv $ISO_LOC
  fi
}

iso_from_dvd () {
  echo -n "Enter Title: " && read ISO_TITLE
  dd if=/dev/sr0 of=$ISO_TITLE.iso
  menu
}

iso_from_directory () {
  echo -n "Enter Full Path of Directory Containing Files: " && read FOR_ISO
  echo -n "Enter Title of Movie for ISO: " && read ISO_TITLE
  genisoimage -V "$ISO_TITLE" -J -r -o $ISO_TITLE.iso $FOR_ISO
  menu
}

burn () {
  echo -n "Enter path/to/image.iso (EX: $(ls *.iso)): " && read ISO_IMG
  growisofs -dvd-compat -Z /dev/sr0=$ISO_IMG
  menu
}

format () {
  ## Alternate:			$ cdrecord -V dev=/dev/sr0 blank=all
  ## Format Without Erasing:	$ dvd+rw-format -force /dev/sr0
  dvd+rw-format -blank=full /dev/sr0
  menu
}

# Main
menu

Offline

#2587 2015-06-13 09:37:37

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Post your handy self made command line utilities

Jakkin wrote:

I've got one to "automate" my system updates and general maintenance. http://pastebin.com/mVM7iF57 What have you done to make your lives easier?

This is not a support thread, but why aren't you using linux-ck repo? https://bbs.archlinux.org/viewtopic.php?id=111715
Running 'pacman -Sc' right after updating your system leaves you with less options when you find out something's broken.


sudo pacman -Syyu
clear

At least in tmux I can scroll back to see pacman's output, there's always pacman.log, but ... why?

Feel free to open a separate thread to discuss your script.

Offline

#2588 2015-06-13 11:35:28

genEric
Member
From: Sweden
Registered: 2013-09-26
Posts: 38

Re: Post your handy self made command line utilities

x33a wrote:

@ genEric, nice!

Thanks x33a…

I guess that adding “!” (exclamation) to the string should probably be good, to get rid of entries like:

!1234
!!

[genEric@…] ~$

Offline

#2589 2015-06-13 21:59:09

Jakkin
Member
From: 403 Forbidden
Registered: 2014-10-16
Posts: 18

Re: Post your handy self made command line utilities

karol wrote:
Jakkin wrote:

I've got one to "automate" my system updates and general maintenance. http://pastebin.com/mVM7iF57 What have you done to make your lives easier?

This is not a support thread, but why aren't you using linux-ck repo? https://bbs.archlinux.org/viewtopic.php?id=111715
Running 'pacman -Sc' right after updating your system leaves you with less options when you find out something's broken.


sudo pacman -Syyu
clear

At least in tmux I can scroll back to see pacman's output, there's always pacman.log, but ... why?

Feel free to open a separate thread to discuss your script.

I have a couple tweaks that I need to make to the kernel (e4rat mainly) which is why I compile it rather than use the linux-ck repo.

sudo pacman -Syyu
clear

Oh, that. That was to clear the screen so I could have an easier time to see whether my kernel needed an update or not. (I've rewritten this script a few times, that "clear" command had gotten moved.)

Thanks for the suggestion with "pacman -Sc". I didn't realize it could cause problems.


Anyone who NEEDS to be TAUGHT how to interact with a computer probably shouldn't be allowed near one. -Sopwith

Offline

#2590 2015-06-13 22:30:54

AaronBP
Member
Registered: 2012-08-06
Posts: 149
Website

Re: Post your handy self made command line utilities

Just wrote a command-line trash manager. Depends on python-docopt & python-gobject. It's basically like gvfs-trash and gvfs-ls 'trash://', with a few differences:

1) This was written by me, so it's probably broken somewhere.
2) It will retrieve files from the trash.
3) --list lists both the filename and the original directory. This is useful information if you want to use --retrieve, have multiple files with the same name, or otherwise just forgot.

#!/usr/bin/python3

"""trash - send files to the trash.

Usage:
    trash -h | --help
    trash -e | --empty
    trash -l | --list
    trash -r | --retrieve <file>...
    trash <file>...

Options:
    -h --help      Show this screen
    -e --empty     Empty trash
    -l --list      Show files in the trash
    -r --retrieve  Retrieve a file from the trash"""

from docopt import docopt
import errno
from gi.repository import Gio, GLib 
import sys

def get_children(uri):
    e = Gio.File.new_for_uri(uri).enumerate_children(
            "*",
            Gio.FileQueryInfoFlags.NONE)
    return e

def rec_delete(file_list):
    for f in file_list:
        if f.get_file_type() == Gio.FileType.DIRECTORY and f.get_attribute_boolean("access::can-delete") == False:
            rec_delete(get_children(f.get_attribute_string("standard::target-uri")))
        file_list.get_child(f).delete()

def empty_trash():
    rec_delete(get_children("trash:"))

def list_trash():
    for trash in get_children("trash:"):
        print("{}\n  {}".format(
            trash.get_attribute_as_string("standard::name"),
            trash.get_attribute_as_string("trash::orig-path")))

def retrieve_trash(f):
    trash_list = get_children("trash:")
    for trash in trash_list:
        if trash.get_attribute_as_string("standard::name") == f:
            trash_list.get_child(trash).move(
                    Gio.File.new_for_path(trash.get_attribute_as_string("trash::orig-path")),
                    Gio.FileCopyFlags.NOFOLLOW_SYMLINKS)
            
def trash(f):
    global exit_code
    try:
        Gio.File.new_for_path(f).trash()
    except GLib.Error as e:
        print("{} -- {}".format(f, e.message), file=sys.stderr)
        exit_code = e.code
    
if __name__ == "__main__":
    global exit_code
    exit_code = 0
    args = docopt(__doc__)
    if args['--empty']:
        empty_trash()
    if args['--list']:
        list_trash()
    try:
        if args['--retrieve']:
            for f in args['<file>']:
                retrieve_trash(f)
        elif args['<file>']:
            for f in args['<file>']:
                trash(f)
    except KeyError:
        pass
    sys.exit(exit_code)

Wrote this after I accidentally rmed something and had to boot into rescue mode to retrieve it...twice. I also wrote a systemd timer that empties the trash once a week. Systemd timers are great.

Offline

#2591 2015-06-16 02:11:18

souenzzo
Member
Registered: 2012-10-31
Posts: 35

Re: Post your handy self made command line utilities

Update flashplugin with one-line

mkdir -p ~/.mozilla/plugins/ && curl -s "http://fpdownload.macromedia.com/get/flashplayer/pdc/$(curl -s 'https://helpx.adobe.com/flash-player/kb/archived-flash-player-versions.html' | grep -o '11\.2\(\.[0-9]\{3\}\)\{2\}' | sort | tail -1)/install_flash_player_11_linux.x86_64.tar.gz" | tar -x -z -C "$HOME/.mozilla/plugins/" "libflashplayer.so"

fix all security bug caused by the script above:

rm ~/.mozilla/plugins/libflashplayer.so

smile

Offline

#2592 2015-06-18 08:02:26

b1tgl0w
Member
Registered: 2011-11-30
Posts: 42

Re: Post your handy self made command line utilities

gccs

Print summary of errors from gcc/g++ on one line.
https://github.com/b1tgl0w/gccs

#!/usr/bin/env perl
my %summary;
while (<>) {
/(.*.(c|h)(pp|c)*):(\d+)(:\d+)?:\serror.*/ and push @{ $summary{$1} }, $4;
print;
}
print "Summary of Errors\n";
foreach $sourcefile ( keys %summary ) {
    print "$sourcefile: @{ $summary{$sourcefile} }\n";
}

Last edited by b1tgl0w (2015-06-18 08:33:58)

Offline

#2593 2015-06-22 20:01:13

grandtheftjiujitsu
Member
Registered: 2013-07-27
Posts: 91

Re: Post your handy self made command line utilities

I was trying to modify the .Xresources color test scripts so that I could temporarily copy the "colors" section of another config, print the new colors, then return to the previous config.  It turned out to be more trouble than it was worth (read not so "handy") when copy / pasting in a trusty text editor works simply and just fine.

Mods can delete this post if you want; or maybe someone more skilled than I can figure it out.

Last edited by grandtheftjiujitsu (2015-06-22 22:07:38)

Offline

#2594 2015-06-23 10:20:30

Saint0fCloud
Member
Registered: 2009-03-31
Posts: 137

Re: Post your handy self made command line utilities

grandtheftjiujitsu wrote:

I was trying to modify the .Xresources color test scripts so that I could temporarily copy the "colors" section of another config, print the new colors, then return to the previous config.  It turned out to be more trouble than it was worth (read not so "handy") when copy / pasting in a trusty text editor works simply and just fine.

Mods can delete this post if you want; or maybe someone more skilled than I can figure it out.

If you copy the color schemes into separate files it's fairly easy to write a script to 'preview' each color scheme and then restore to the original, kind of like this https://gist.github.com/jsks/11323851.

Offline

#2595 2015-06-24 00:46:03

grandtheftjiujitsu
Member
Registered: 2013-07-27
Posts: 91

Re: Post your handy self made command line utilities

Saint0fCloud wrote:

If you copy the color schemes into separate files it's fairly easy to write a script to 'preview' each color scheme and then restore to the original, kind of like this https://gist.github.com/jsks/11323851.

Nice find, Thanks!

Offline

#2596 2015-06-29 15:30:23

Jakkin
Member
From: 403 Forbidden
Registered: 2014-10-16
Posts: 18

Re: Post your handy self made command line utilities

Dumping .bashrc and general use scripts.

 1 #
# ~/.bashrc
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

alias ls='ls --color=auto'
PS1='[\u@\h \W]\$ '

HISTSIZE=9999
HISTFILESIZE=20000

alias msfconsole="msfconsole --quiet -x \"db_connect ${USER}@msf\""

export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
alias start='sudo systemctl start' # Simplifies starting services.
export PATH="~/.scripts:$PATH" # A "script repository" in a way. My most used scripts find their way into this folder.
alias status='systemctl status' # Easy status checking of my services/
export EDITOR="vim"

~/.scripts dump.
EDIT: I've been playing around with this one. It might change a few times.
ipaddress

ip -o -4 addr show | gawk '{ print $2, "\t", $4 }' | cut -d / -f 1 # Shows just my ip address. It's still a work in progress, though.

switch

cp /etc/makepkg.conf.pacnew /etc/makepkg.conf # My pacnew file holds my configured compile flags. I should probably copy it to a file that isn't likely to be overwritten...

switcheroo

cp /etc/makepkg.conf.backup /etc/makepkg.conf # The makepkg.conf.backup file holds the original compile flags. I use this if my custom flags don't work.

wireless

watch -n 1 "awk 'NR==3 {print \"WiFi Signal Strength = \" \$3 \"00 %\"}''' /proc/net/wireless" # This tells me how strong the wireless signal is in percentages. Its probably useless, but kinda fun.

maint (Yup, I updated it again.)

sudo pacman -Sc

sudo wget -O /etc/pacman.d/mirrorlist https://www.archlinux.org/mirrorlist/all/ && 
sudo cp /etc/pacman.d/mirrorlist.backup /etc/pacman.d/mirrorlist && 
sudo reflector -l 20 -p http --sort rate --save /etc/pacman.d/mirrorlist;

curl -s https://aur.archlinux.org/packages/li/linux-ck/PKGBUILD | grep pkgver= > .pkgver
curl -s https://aur.archlinux.org/packages/li/linux-ck/PKGBUILD | grep pkgrel= > .pkgrel

if [ `uname -r` == `echo "$(cat ./.pkgver | sed -r 's/^.{7}//')-$(cat ./.pkgrel | sed -r 's/^.{7}//')-ck"` ]; then
	zenity --info --text="No update needed."
else
        zenity --info --text="Update needed."
	yaourt linux-ck
        sudo grub-mkconfig -o /boot/grub/grub.cfg;
fi

rm .pkgver
rm .pkgrel

sudo etckeeper pre-install
sudo pacman -Syyu; #Updates system.
sudo etckeeper post-install

sudo pacman -Rcns $(pacman -Qtdq)

sudo pacman-optimize; #Optimizes pacman cache.

EDIT: Added etckeeper to maint script.

Last edited by Jakkin (2015-07-08 00:37:04)


Anyone who NEEDS to be TAUGHT how to interact with a computer probably shouldn't be allowed near one. -Sopwith

Offline

#2597 2015-07-12 18:29:32

AaronBP
Member
Registered: 2012-08-06
Posts: 149
Website

Re: Post your handy self made command line utilities

For anyone using neovim, I wrote nvim-command. This is handy for writing scripts to be run in a neovim :term. Actually wrote this last week but forgot to share it here.
https://gist.github.com/BPaden/e52047b63b5339ebf835

Last edited by AaronBP (2015-07-12 18:30:13)

Offline

#2598 2015-07-15 20:29:07

null
Member
Registered: 2009-05-06
Posts: 398

Re: Post your handy self made command line utilities

Trying to force myself into instantly merging *.pacnew files:

function pacnew {
	sdiff -s -H -b $1 $1.pacnew -o $1.tmpmerge;
	sdr=$?
	if [ $sdr = "0" ]; then
		echo "Both files are the same. Deleting pacnew file"
		rm $1.pacnew
		return 0;
	elif [ $sdr = "1" ]; then
		while true; do
			echo "Use merged File and delete others? [n/y] " 
			read -s reply
			case $reply in
				[yY][eE][sS]|[yY])
					mv $1.tmpmerge $1
					rm $1.pacnew
					return 0
					;;
				[nN][oO]|[nN])
					return 0
					;;
				*)
					;;
			esac
		done
	fi
}

function pacman {
	if [ $1 = "-Syu" ]; then
		/usr/bin/pacman $@
		for file in $(tac /var/log/pacman.log|awk '/starting full system upgrade/{if(b) exit; else b=1}1'|awk '/pacnew/{print $5}'); do
			echo "Merge $file:"
			pacnew $file
		done
	else
		/usr/bin/pacman $@
	fi	
}

(not well tested. May break stuff..)

Last edited by null (2015-07-15 20:29:27)

Offline

#2599 2015-07-15 22:02:35

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Post your handy self made command line utilities

Why not use pacdiff or https://bbs.archlinux.org/viewtopic.php?id=76261 ?

If the files are the same, there should be no pacnew.

Offline

#2600 2015-07-16 09:34:10

null
Member
Registered: 2009-05-06
Posts: 398

Re: Post your handy self made command line utilities

Yeah. I didn't knew about them.
But I think I prefer to be prompted with sdiff (freebsd mergeinstall habit) direktly after any update and only for any new pacnew files. If there are older pacnew files there might be a good reason for it.

Offline

Board footer

Powered by FluxBB