You are not logged in.
Carrying on from #! forum's thread. What useful one-liners, aliases or functions do the bunsenlabbers have up their sleeves. Feel free to build and adjust on what is posted from one another.
#Open a random crunchbang forum thread
xdg-open http://crunchbang.org/forums/viewtopic.php?pid=$(echo $[ 200 + $[ RANDOM % 3000000 ]])
Works 90% of the time.
Might have to play with a bit seems to mostly pick older threads.
Good nuf* hmph.
#Open the website of an installed program
aptsite () { xdg-open $(apt-cache show $1 | grep '\<http.*\>' | awk '{print $2}') &>/dev/null || echo nope ; }
Offline
Good idea!
Can I suggest a slight simplification of that handy aptsite () function?
You don't need both grep and awk to extract the url - either can do it alone:
apt-cache show "$1" | grep -o 'http:[^ ]*'
apt-cache show "$1" | awk '/http:/{print $2}
The time taken is about the same though...
The app name is only one word so the quotes aren't needed round "$1", but it doesn't hurt.
...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )
Offline
These are my current aliases. Always a work in progress borrowing ideas here and there.
.bash_aliases
alias al='cat ~/.bash_aliases'
alias xe='eval `slmenu -p ">>>" < ~/.slmenu` '
alias bre='source ~/.bashrc'
alias xre='xrdb -merge ~/.Xresources'
alias alsamixer="alsamixer -g"
alias fonts='sudo fc-cache -fv'
alias mem='sudo ps_mem.py'
alias c='clear'
alias fehb='feh --bg-scale'
alias fehbc='feh --bg-center'
alias fehbf='feh --bg-fill'
alias fehbs='feh --bg-scale'
alias preview='feh -g 1600x1050+500+200 -R .01 --zoom fill'
alias running='PS_FORMAT="user,pid,pcpu,pmem,start,args" ps axf'
alias wget='wget -c'
alias date='date "+%A, %B %d, %Y [%I:%M %P]"'
alias md='mkdir -p -v'
alias rd='rmdir -v'
alias manb='man -H'
# apt & dpkg
alias upd='sudo apt update'
alias upg='sudo apt update && sudo apt dist-upgrade'
alias ins='sudo apt install'
alias get-='sudo apt-get install --no-install-recommends'
alias reinstall='sudo apt-get install --reinstall'
alias purge='sudo apt purge'
alias apurge='sudo apt-get autoremove --purge'
alias orphans='sudo deborphan | xargs sudo apt-get -y remove --purge'
alias clean='sudo apt-get clean'
alias cleanup='sudo apt-get autoclean && sudo apt-get autoremove && sudo apt-get clean && sudo apt-get remove && orphand'
alias search='apt-cache search'
alias isearch='apt-cache --installed search'
alias policy='apt-cache policy'
alias show='apt-cache show'
alias depends='apt-cache depends'
alias held='sudo dpkg --get-selections | grep hold'
alias bugs='apt-listbugs list'
# inxi
alias inx='inxi -Fz -c6' ## filtered
alias INX='inxi -F -c6' ## not filtered
alias inxs='inxi -zv7'
alias SYS='inxi -ACDfGIpluNrsSt cm3 -x -v7 -c6' ## not filtered
alias sys='inxi -ACDfGIpluNrsSt cm3 -x -v7 -c6 -z' ## Filtered
# Search
alias where="which"
alias what="apropos"
alias apr="apropos"
alias ff="find . -type f -name"
# Navigation
alias cdls='cd $1 && ls'
alias goto='OPTIONS=$(\ls -F | grep /$); select s in $OPTIONS; do cd $PWD/$s; break;done'
alias back='cd "$OLDPWD"'
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../../"
alias ......="cd ../../../../.."
alias home='cd ~/'
alias documents='cd ~/Documents'
alias downloads='cd ~/Downloads'
alias images='cd ~/Pictures'
alias videos='cd ~/Videos'
alias music='cd ~/Music'
alias bin="cd $HOME/.local/bin"
# Safety
alias rm='rm -Iv --preserve-root'
alias mv='mv -iv'
alias cp='cp -iv'
alias ln='ln -i'
# Power
alias reboot='sudo /sbin/reboot'
alias poweroff='sudo /sbin/poweroff'
alias halt='sudo /sbin/halt'
alias shutdown='sudo /sbin/shutdown'
# List
alias ls="ls -lha"
alias la='ls -A'
alias ll='ls -l'
alias lf='ls -F --color=auto --group-directories-first'
alias big='ls -laSh | head'
# color
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
Last edited by Snap (2015-10-24 08:04:37)
Offline
apt-cache show "$1" | grep -o 'http:[^ ]*' apt-cache show "$1" | awk '/http:/{print $2}
Nifty johnraff, and a much cleaner approach. thank you.
You're certainly right about quoting "$1" I forget this all too often.
Thinking again I didn't need the awk pipe in my original either as.. grep -o '\<http.*\>' ..seems to do the trick as well.
Offline
select choice:
alias du1='du -m --max-depth=1|sort -g|sed "s/\t./M\t/g ; s/\///g"'
alias find='find 2>/dev/null'
alias hf='history|grep'
alias mpf='/usr/bin/ls -1 | mpv --playlist=-' (*)
alias ruler='xmeasure '
alias stressme='stress --cpu 8 --io 4 --vm 2 --vm-bytes 128M --timeout'
alias sx='exec startx'
alias xg='xgamma -gamma'
(*)
i got this from somewhere, but never actually use it, because usually "mpv *" is sufficient.
Last edited by ohnonot (2015-10-24 08:18:57)
Offline
.zshrc from my ThinkPad:
light() { xbacklight -set $1 }
orphan() { [[ ! -n $(pacman -Qdt) ]] && echo All clear! || sudo pacman -Rns $(pacman -Qqdt) }
export EDITOR=/usr/bin/vim
export VISUAL=/usr/bin/vim
export BROWSER=/usr/bin/firefox
export SYSTEMD_EDITOR=/usr/bin/vim # doesn't bloody work -- it still loads nano! :(
alias sudo='/usr/bin/sudo'
alias su='/usr/bin/su'
alias passwd='/usr/bin/passwd'
alias mv='mv -iv'
alias rm='rm -Iv'
alias cp='cp -iv'
if [[ -z "$TMUX" ]] ;then
ID="`tmux ls | grep -vm1 attached | cut -d: -f1`"
if [[ -z "$ID" ]] ;then
tmux new-session
else
tmux attach-session -t "$ID"
fi
fi
Offline
alias lst='ls -clhtr'
lst, list by date, newer last
du -hca --max-depth=1 "$@" | sort -h
duh, list by size, fater last
du -ak "$@" | sort -n | awk -F '\t' -v OFS='\t' '{if ($1 > 1048576) $1 = sprintf("%.1fG",$1/1048576); else if ($1 > 1024) $1 = sprintf("%.1fM",$1/1024); else $1 = sprintf("%sK",$1)} 1'
duh, mac version
Last edited by brontosaurusrex (2015-10-24 11:18:31)
Offline
These are my current aliases. Always a work in progress borrowing ideas here and there.
alias al='cat ~/.bash_aliases'
Here's one you might like since bash already knows where your alias file is and 'alias' just works.
alias al='alias | less'
OR ... (mine is in a different place):
alias al='nano ~/bin/Bash/bash_aliases'
This way it's in colour AND
it isn't listed in alpha order AND
still has my commented sections AND
if I want to edit it - I can. :)
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline
Apart from all the usual `ls` and `apt` aliases, here are some I use all the time:
#get usb's before using dd!
alias usb='ls -l /dev/disk/by-id/*usb* | awk {'\''print ($11)'\''} | cut -c 7-$NF'
# get xevents without being swamped by mouse movements
alias xxev='xev -g +730+10 | sed "/^MotionNotify/,/^$/d"'
# updatedb databases
## update /home
alias upd8home='sudo updatedb -v -U /home/damo -o /var/lib/mlocate/home.db --prunepaths=/home/damo/.local/share/Trash'
## update backups
alias upd8bkp='sudo updatedb -v -U /mnt/backups -o /var/lib/mlocate/backups.db'
## update /
alias upd8all='sudo updatedb -v --prunepaths="/home/damo/.local/share/Trash /mnt/windoze /mnt/backups /mnt/data /var/spool /var/tmp /tmp"'
## update Trash
alias upd8trash='sudo updatedb -v -U /home/damo/.local/share/Trash/files -o /var/lib/mlocate/trash.db'
## locate files from mlocate databases
alias loc8home='locate -d /var/lib/mlocate/home.db'
alias loc8bkp='locate -d /var/lib/mlocate/backups.db'
alias loc8all='locate'
alias loc8trash='locate -d /var/lib/mlocate/trash.db'
...and 2 of the best ever
## search crunchbang/bunsenlabs forums with "cbs|bls <searchterm>"
alias cbs="surfraw -g google site:crunchbang.org/forums"
alias bls="surfraw -g google site:forums.bunsenlabs.org"
Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
Some aliases I find useful.
alias uu='sudo apt-fast update && sudo apt-fast dist-upgrade -y'
alias get='sudo apt-fast install -y'
alias rem='sudo apt-get autoremove'
alias cl='sudo apt-get autoclean'
alias se='apt-cache search'
alias md='mkdir'
alias sd='sudo shutdown -h now'
alias rb='sudo shutdown -r now'
alias prg='sudo apt-get purge'
alias ls='ls -F --color --group-directories-first'
alias c='clear'
alias q='exit'
alias s='sudo'
alias al='cat ~/.bash_aliases'
That last one is probably one of the most useful ones. Great for geezers with shaky memories. I also thought what sector11 posted about that was interesting. I think I'll add "aln" for editing my aliases with nano after seeing that.
Another idea that just came to me. If one has a short enough list they could put aliases in conky just like the keyboard shortcuts.
Note: My aliases for updating, upgrading, and installing software include the -y tag so that prompts are answered with yes automagically. I put this in due to the way apt-fast works and it expedites things. I am running sid but apt-listbugs is not affected by the -y and still allows for checking bugs before upgrading or installing. If it finds no bugs then things just go ahead as normal.
Last edited by MAC the Bloody (2015-10-24 17:09:38)
“The university is well structured, well tooled, to turn out people with all the sharp edges worn off...." Mario Savio
"Protections for anonymous speech are vital to democratic discourse". Help enforce our right to free and anonymous speech by running a Tor relay.
Offline
Useful for checking service status without mixing the two outputs.
alias statoff='service --status-all | grep -w -'
alias staton='service --status-all | grep +'
you could run them together for ordered output
staton ; statoff
and a dmenu calculator #had this for a while, think I hijacked from arch thread.
alias dcalc='xsel -o | dmenu -p Calculate: | xargs echo | bc 2>&1 | dmenu -p Answer: | xsel -i'
Some file functions:
# Maybe cleaner approach. Also, added a backup on first line for safety sake. probably safe to remove.
sorttofile () {
cp $1{,.bak}; echo "$1... $1.bak"
sleep 1s
cat $1 | sort > tmmp && cat tmmp > $1
rm tmmp
cat $1
}
# copies file and appends date to name.
cpdate () {
date=$( date +%F )
cp $1 $1_$date
}
Offline
List all enabled systemd .services & .sockets:
alias list='systemctl list-unit-files|grep enabled'
Useful for debugging network problems and slimming down the system.
empty@ThinkPad ~ % list
getty@.service enabled
nftables.service enabled
ntpd.service enabled
systemd-networkd.service enabled
systemd-resolved.service enabled
wpa_supplicant@.service enabled
systemd-networkd.socket enabled
Offline
a function to remind you how to do stuff, you could then call this function with an alias (if you wanted to shorten the name) , or dont use an alias and just type the name of the function.
alias vsr ='vim-search-replace'
vim-search-replace() { # {{{
cat <<EOF
:s/foo/bar/g Change each 'foo' to 'bar' in the current line.
:%s/foo/bar/g Change each 'foo' to 'bar' in all lines.
:5,12s/foo/bar/g Change each 'foo' to 'bar' for all lines from line 5 to line 12 inclusive.
:'a,'bs/foo/bar/g Change each 'foo' to 'bar' for all lines from mark a to mark b inclusive.
:.,$s/foo/bar/g Change each 'foo' to 'bar' for all lines from the current line (.)
to the last line ($) inclusive.
:.,+2s/foo/bar/g Change each 'foo' to 'bar' for the current line (.) and the two next lines (+2).
:%s/foo/bar/g Equivalent to :1,$s/foo/bar/g (change all lines).
:g/^baz/s/foo/bar/g Change each 'foo' to 'bar' in each line starting with 'baz'.
EOF
}
#============
Last edited by shot-in-the-head (2016-06-23 11:06:53)
Offline
Apart from all the usual `ls` and `apt` aliases, here are some I use all the time:
... # get xevents without being swamped by mouse movements alias xxev='xev -g +730+10 | sed "/^MotionNotify/,/^$/d"' ...
...
If it's just for finding keycodes/keysyms, can't one instead use xev -event keyboard to reduce noise?
And if one just wants a single keycode/keysym at a time, then this may suffice:
xev -event keyboard | grep -m 1 -A 4 "KeyPress event"
and for use with the "shift" key
xev -event keyboard | grep -m 2 -A 4 "KeyPress event"
Edit: there's no need for "-event keyboard" because grep cleans up things.
Example output:
07:30 PM ~/Desktop $ xev -event keyboard | grep -m 1 -A 4 "KeyPress event"
KeyPress event, serial 28, synthetic NO, window 0x2800001,
root 0x7e, subw 0x0, time 16360116, (609,530), root:(1293,593),
state 0x0, keycode 34 (keysym 0x5b, bracketleft), same_screen YES,
XLookupString gives 1 bytes: (5b) "["
XmbLookupString gives 1 bytes: (5b) "["
07:33 PM ~/Desktop $ xev -event keyboard | grep -m 2 -A 4 "KeyPress event"
KeyPress event, serial 28, synthetic NO, window 0x2800001,
root 0x7e, subw 0x0, time 16378626, (609,530), root:(1293,593),
state 0x0, keycode 50 (keysym 0xffe1, Shift_L), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
--
KeyPress event, serial 28, synthetic NO, window 0x2800001,
root 0x7e, subw 0x0, time 16379162, (609,530), root:(1293,593),
state 0x1, keycode 34 (keysym 0x7b, braceleft), same_screen YES,
XLookupString gives 1 bytes: (7b) "{"
XmbLookupString gives 1 bytes: (7b) "{"
07:33 PM ~/Desktop $
Oops! This is even briefer:
xev | awk -F'[ )]+' '/^KeyPress/ { a[NR+2] } NR in a { printf "%-3s %s\n", $5, $8 }'
from https://wiki.archlinux.org/index.php/Ex … ys#In_Xorg
Last edited by vasa1 (2015-11-09 04:52:38)
Using the Openbox (3.5.2) session of Lubuntu 14.04 LTS but very interested in BL :)
Offline
I would like to use something like the following as root: alias dwn='cd /home/username/Downloads/'
Where do I have to create a .bash_aliases file, so I can use 'dwn' for getting to that folder as root?
Offline
I would like to use something like the following as root: alias dwn='cd /home/username/Downloads/'
Where do I have to create a .bash_aliases file, so I can use 'dwn' for getting to that folder as root?
You can put aliases in '~/bashrc', otherwise use:
~/bash_aliases
NB You will have to investigate how sudo works in that situation though. You can add the alias in the current shell on the commandline to test it out.
[damo@hydrogen ~]$ alias dwn='cd /home/damo/Downloads/'
Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
@damo Thank you for the answer. Indeed, it works from the command line (both for user and root) and there is also /root/bashrc, which can be used for aliases for root. It seems one has to open a new terminal and log in again as root in order to use aliases after bashrc was changed.
Edit: This is so cool! If someone puts
alias wtr='curl -4 wttr.in/bunsen'
in ~/.bash_aliases, you will get bunsen-weather in the terminal after the "wtr" weather-command!
Of course "bunsen" can be also replaced with any other city (btw strange country for bunsen...) .
Last edited by martix (2016-05-04 14:37:10)
Offline
After editing .bashrc or .bash_aliases, to get an immediate effect for other user shells (without logging out/in) you need to do
source .bashrc
Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
@damo I see, good to know, cheers!
Offline
I always forget the commands for listing files in archives...
# list files in a tar archive
alias ltar='tar tf'
# list files in a zip archive
alias lzip='unzip -l'
This one's also pretty neat
# create a temp directory and cd into it
alias cdtmp='cd "$(mktemp -d)"'
Offline