40 votes

Whats the most important alias or function in your bashrc file?

Hello new member here to Tildes!

I just wanted to see what all people are putting in their bashrc file that makes them more productive?

73 comments

  1. [3]
    unknown user
    Link
    This one, by far: l() { if [[ -n "$1" ]]; then if [[ -d "$1" ]]; then ls -- "$1" elif [[ -f "$1" ]]; then less -- "$1" else # It's probably a flag ls "$@" fi else ls . fi } If you run l on a file,...

    This one, by far:

    l() {
    	if [[ -n "$1" ]]; then
    		if [[ -d "$1" ]]; then
    			ls -- "$1"
    		elif [[ -f "$1" ]]; then
    			less -- "$1"
    		else
    			# It's probably a flag
    			ls "$@"
    		fi
    	else
    		ls .
    	fi
    }
    

    If you run l on a file, it opens it in less (I now use bat because I like the syntax highlighting, but honestly I might switch back at some point); if you l a directory, it runs ls.

    It has several deficiencies, but it works well enough for me.

    17 votes
    1. [2]
      papasquat
      Link Parent
      What are the deficiencies, it you don't mind me asking?

      What are the deficiencies, it you don't mind me asking?

      1 vote
      1. unknown user
        Link Parent
        The fact that it doesn't handle multiple arguments at all is the biggest one – I try to use it with a glob fairly often, but it just acts upon the first argument. Probably you'd just want to test...

        The fact that it doesn't handle multiple arguments at all is the biggest one – I try to use it with a glob fairly often, but it just acts upon the first argument.

        Probably you'd just want to test if the number of arguments is greater than 1, and if so then just unconditionally call ls.

        1 vote
  2. [10]
    acdw
    Link
    Honestly, the one I probably use the most is alias e=$EDITOR It saves so much typing, and now it's muscle memory. First thing I do on a new install.

    Honestly, the one I probably use the most is

    alias e=$EDITOR
    

    It saves so much typing, and now it's muscle memory. First thing I do on a new install.

    10 votes
    1. [7]
      jenz
      Link Parent
      Haha, I came here to post: alias e=exit

      Haha, I came here to post:

      alias e=exit
      
      9 votes
      1. [6]
        acdw
        Link Parent
        Hilarious! I wonder what other one-letter aliases there are. I have v=$PAGER as well, but I hardly ever use it. And to exit, I just Ctrl-D :)

        Hilarious! I wonder what other one-letter aliases there are. I have v=$PAGER as well, but I hardly ever use it. And to exit, I just Ctrl-D :)

        3 votes
        1. [5]
          spit-evil-olive-tips
          Link Parent
          I have a few one-letter or very-abbreviated ones: alias sys='sudo systemctl' alias sus='systemctl --user' alias root='sudo su -l' alias d=docker alias jef='journalctl -ef' alias je='journalctl -e'...

          I have a few one-letter or very-abbreviated ones:

          alias sys='sudo systemctl'
          alias sus='systemctl --user'
          alias root='sudo su -l'
          alias d=docker
          
          alias jef='journalctl -ef'
          alias je='journalctl -e'
          alias jf='journalctl -f'
          alias j='journalctl'
          
          3 votes
          1. [4]
            acdw
            Link Parent
            I have a lot of sudo aliases too, I actually use a loop for them: for cmd in (shutdown reboot pacman); do alias $cmd="sudo $cmd" done I think that's right; I'm at work right now so I'm not 100%...

            I have a lot of sudo aliases too, I actually use a loop for them:

            for cmd in (shutdown reboot pacman); do
                alias $cmd="sudo $cmd"
            done
            

            I think that's right; I'm at work right now so I'm not 100% sure if that's the way it's written.

            3 votes
            1. [3]
              unknown user
              Link Parent
              Assuming you're not using Fish, you probably don't want the parens – that'll run shutdown reboot pacman in a subshell, which probably will just complain about the arguments, but if you're unlucky...

              Assuming you're not using Fish, you probably don't want the parens – that'll run shutdown reboot pacman in a subshell, which probably will just complain about the arguments, but if you're unlucky might shut down your computer.

              2 votes
              1. [2]
                acdw
                Link Parent
                Oh no, I wanted it to be an array! I guess I can just list out the commands right, without parentheses?

                Oh no, I wanted it to be an array! I guess I can just list out the commands right, without parentheses?

                1. unknown user
                  Link Parent
                  Yep, that should work.

                  Yep, that should work.

                  1 vote
    2. [2]
      Ephemere
      Link Parent
      I do something very similar, with e=cd, o=ls, u=$EDITOR. I use a dvorak keyboard, so all of the home row vowels map to a common function. Of course, I'm trying to use eshell more, so having all of...

      I do something very similar, with e=cd, o=ls, u=$EDITOR. I use a dvorak keyboard, so all of the home row vowels map to a common function.

      Of course, I'm trying to use eshell more, so having all of these in my muscle memory is starting to be more trouble than anything else, as I've been too lazy to mirror them.

      2 votes
      1. acdw
        Link Parent
        I was about to ask what the mnemonic was for you, but then I saw your "home row vowels;" neat!

        I was about to ask what the mnemonic was for you, but then I saw your "home row vowels;" neat!

        1 vote
  3. kiddico
    Link
    fuck(){ sudo bash -c "$(history -p \!\!)"; } and alias cls="clear; pwd-P; ls -1" fuck reruns the last command with sudo. cls cleans the crap off my screen and gives me context for where I am. My...
    fuck(){
    	sudo bash -c "$(history -p \!\!)";
    }
    

    and

    alias cls="clear; pwd-P; ls -1"
    

    fuck reruns the last command with sudo.

    cls cleans the crap off my screen and gives me context for where I am. My brain for some reason can't handle having tons of stuff from previous commands, so clearing everything out is nice. It's kinda like turning down the radio when driving in bad weather.

    10 votes
  4. [4]
    emilburzo
    Link
    If the only criteria is "more productive", then: (by a long shot) source /etc/profile.d/autojump.bash (autojump) Second place: export HISTSIZE=500000 export HISTFILESIZE=1000000 export...

    If the only criteria is "more productive", then: (by a long shot)

    source /etc/profile.d/autojump.bash
    

    (autojump)

    Second place:

    export HISTSIZE=500000
    export HISTFILESIZE=1000000
    export HISTCONTROL=ignoredups:erasedups
    

    (history long enough to keep all my frequently used commands)

    Third:

    alias grep="grep --color=auto"
    

    (highlights matches, with color, when grepping)

    9 votes
    1. [2]
      Comment deleted by author
      Link Parent
      1. emilburzo
        Link Parent
        I would say no, for servers if there's anything repetitive it usually gets automated, so autojump wouldn't be useful. For other people's computers I wouldn't know their paths anyway. Dangerous...

        I would say no, for servers if there's anything repetitive it usually gets automated, so autojump wouldn't be useful.

        For other people's computers I wouldn't know their paths anyway.

        Dangerous one-letter aliases on the other hand...

        1 vote
    2. brandons
      Link Parent
      Oh dang I didn't know about the color flag on grep. Thanks!

      Oh dang I didn't know about the color flag on grep. Thanks!

      1 vote
    3. weystrom
      (edited )
      Link Parent
      I'll tag along. This allows me to share history between bash sessions/tabs/windows, helps to quickly ctl+r a thing I've just typed in a different window and just have more confidence in history...

      I'll tag along. This allows me to share history between bash sessions/tabs/windows, helps to quickly ctl+r a thing I've just typed in a different window and just have more confidence in history lookup overall:

      # append to history, don't overwrite it
      shopt -s histappend
      # Save and reload the history after each command finishes
      export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
      
  5. [5]
    gyrozeppeli
    Link
    v for (neo)vim.

    v for (neo)vim.

    9 votes
    1. [4]
      confusedninja
      (edited )
      Link Parent
      same here. alias s=sudo alias m='mpv --no-video' alias h=htop alias p=python alias sp='sudo alias ..='cd ..'

      same here.

      alias s=sudo
      alias m='mpv --no-video'
      alias h=htop
      alias p=python
      alias sp='sudo 
      alias ..='cd ..'
      
      3 votes
      1. gyrozeppeli
        Link Parent
        Ah, I've been using zsh for so long I'd forgotten that .. being aliased to 'cd ..' wasn't the default. I also alias a bunch of common directories I go to– my sync(dropbox alternative) folder, my...

        Ah, I've been using zsh for so long I'd forgotten that .. being aliased to 'cd ..' wasn't the default.

        I also alias a bunch of common directories I go to– my sync(dropbox alternative) folder, my work/official repos folder, etc.

        4 votes
      2. [2]
        jenz
        Link Parent
        As a fan of [Crystal][cr]: alias cr=crystal And why don't people use syntax highlighting? [cr]: https://crystal-lang.org

        As a fan of [Crystal][cr]:

        alias cr=crystal
        

        And why don't people use syntax highlighting?
        [cr]: https://crystal-lang.org

        1 vote
        1. confusedninja
          Link Parent
          Fixed Happy? :)

          And why don't people use syntax highlighting?

          Fixed Happy? :)

          1 vote
  6. [4]
    Diff
    (edited )
    Link
    My desktop's name is Chalupa, and it controls the lighting, so on my laptop I have an alias called Chalupa that SSHes in, sets up some environment variables, then executes whatever command. So...

    My desktop's name is Chalupa, and it controls the lighting, so on my laptop I have an alias called Chalupa that SSHes in, sets up some environment variables, then executes whatever command. So chalupa blinc black to shut the lights off at night. Or chalupa ytplay "Benny Hill Theme" to search youtube and play whatever.

    9 votes
    1. [3]
      Abrown
      Link Parent
      Please tell me your desktop's name is Enchilada

      Please tell me your desktop's name is Enchilada

      1 vote
      1. [2]
        Diff
        Link Parent
        Close. Few similar letters, anyway. Laptop is Empanada.

        Close. Few similar letters, anyway. Laptop is Empanada.

        1 vote
        1. Abrown
          Link Parent
          Ahh, of course, of course. I don't have a creative bone in my body and simply refer to my devices by the final part in their private IP -- '7', '3', '8', etc

          Ahh, of course, of course. I don't have a creative bone in my body and simply refer to my devices by the final part in their private IP -- '7', '3', '8', etc

          2 votes
  7. minimaltyp0s
    Link
    Just a few simple ones for me that I've added over time: alias myip="ipconfig getifaddr en0" alias ll="ls -alhGF" alias dedup="pbpaste | sort | uniq | pbcopy" alias md5='openssl md5' alias...

    Just a few simple ones for me that I've added over time:

    alias myip="ipconfig getifaddr en0"
    alias ll="ls -alhGF"
    alias dedup="pbpaste | sort | uniq | pbcopy"
    alias md5='openssl md5'
    alias sha1='openssl sha1'
    alias extip="curl ifconfig.co"
    

    Getting IP addresses is obvious. The hash aliases were used when I was doing some CTF exercises and needed a way of generating some hashes quickly in the shell for a given set of words so it was nice to be able to pipe values into it. The dedup one was when I was working with a lot of manual data compilation from horrible, horrible, disparate sources for a client and I wanted a quick way of cleaning data I'd copy and pasted.

    6 votes
  8. [5]
    confusedninja
    (edited )
    Link
    I forgot where i found this one but here it is # extract - archive extractor extract () { if [ -f $1 ] ; then case $1 in *.tar.bz2) tar xjf $1 ;; *.tar.gz) tar xzf $1 ;; *.bz2) bunzip2 $1 ;;...

    I forgot where i found this one but here it is

    # extract - archive extractor
    extract () {
        if [ -f $1 ] ; then
            case $1 in
                *.tar.bz2)   tar xjf $1   ;;
                *.tar.gz)    tar xzf $1   ;;
                *.bz2)       bunzip2 $1   ;;
                *.rar)       unrar x $1     ;;
                *.gz)        gunzip $1    ;;
                *.tar)       tar xf $1    ;;
                *.tbz2)      tar xjf $1   ;;
                *.tgz)       tar xzf $1   ;;
                *.zip)       unzip $1     ;;
                *.Z)         uncompress $1;;
                *.7z)        7z x $1      ;;
                *)           echo "'$1' cannot be extracted via ex()" ;;
            esac
        else
            echo "'$1' is not a valid file"
        fi
    }
    
    6 votes
    1. [3]
      emilburzo
      Link Parent
      Not as convenient as a bash-only thing, but you might want to look at atool My favorite is just aunpack <any-kind-of-archive>, which does what you posted but with some extra nice stuff. For...

      Not as convenient as a bash-only thing, but you might want to look at atool

      My favorite is just aunpack <any-kind-of-archive>, which does what you posted but with some extra nice stuff.

      For example, if it's just an archive of files on the root level, it will create a folder first and dump them in there, instead of littering your current folder.

      4 votes
      1. tesseractcat
        Link Parent
        Another tool that does something similar is dtrx, which is available via the Ubuntu package manager which makes it really convenient for extracting lots of different things.

        Another tool that does something similar is dtrx, which is available via the Ubuntu package manager which makes it really convenient for extracting lots of different things.

  9. vsd
    Link
    May be off topic since you specified bashrc, but using zsh with the git plugin saves me tons of time. I often type gst = git status gl = git pull gcmsg = git commit -m gp = git push so saves me...

    May be off topic since you specified bashrc, but using zsh with the git plugin saves me tons of time. I often type
    gst = git status
    gl = git pull
    gcmsg = git commit -m
    gp = git push
    so saves me lots of time for git stuff.

    In my .zshrc I also have aliases to cd to common repos, I just type
    cdv = cd V_repo
    cdl = cd L_repo
    where v and l are the first letters of some of my repos.

    5 votes
  10. teaearlgraycold
    Link
    I'll cheat and post two: alias whoops='git commit -a --amend --no-edit && git push --force-with-lease' Add all changes to tracked files to the previous commit and force push to origin. and...

    I'll cheat and post two:

    alias whoops='git commit -a --amend --no-edit && git push --force-with-lease'
    

    Add all changes to tracked files to the previous commit and force push to origin.

    and

    function git_branch() {
        git rev-parse --abbrev-ref HEAD 2> /dev/null
    }
    
    function git_prompt() {
        local branch=$(git_branch)
        local deltas=$(git rev-list --left-right --count $branch...origin/$branch 2> /dev/null)
    
        if ! [ -z "$branch" ]; then
            echo -n "[\[\033[0;36m\]$branch\[\033[0m\]"
    
            if ! [ -z "$deltas" ]; then
                local ahead=$(echo $deltas | awk '{ print $1 }')
                local behind=$(echo $deltas | awk '{ print $2 }')
    
                echo -n " | "
                echo -n "↓\[\033[0;31m\]$behind\[\033[0m\] "
                echo -n "↑\[\033[0;32m\]$ahead\[\033[0m\]"
            fi
    
            echo "] "
        fi
    }
    
    function prompt() {
        PS1="\u@\h:\w\\$\[$(tput sgr0)\] $(git_prompt)"
    }
    
    PROMPT_COMMAND=prompt
    

    This will make your PS1 look like:

    teaearlgraycold@supercomputer:~/git/project-foo$ [master | ↓0 ↑1]
    

    when you're in a git repo.

    5 votes
  11. [8]
    just_a_salmon
    Link
    alias u="cd .."

    alias u="cd .."

    4 votes
    1. [5]
      unknown user
      Link Parent
      Not really useful, but I just did the following to take a break from studying: alias right='cd "$(dirname $PWD)/$( OLDPWD=$PWD cd .. && for p in *; do if [ -d $p ]; then echo $p; fi; done | sort |...

      Not really useful, but I just did the following to take a break from studying:

      alias right='cd "$(dirname $PWD)/$( OLDPWD=$PWD cd .. && for p in *; do if [ -d $p ]; then echo $p; fi; done | sort | grep -A 1 $(basename $OLDPWD) | tail -1 )"'
      alias left='cd "$(dirname $PWD)/$( OLDPWD=$PWD cd .. && for p in *; do if [ -d $p ]; then echo $p; fi; done | sort | grep -B 1 $(basename $OLDPWD) | head -1 )"'
      

      These go to the next or previous directory, alphabetically, under the same tree as $PWD. Gues -1 to head and tail is a GNUism.

      2 votes
      1. [4]
        Crestwave
        Link Parent
        Why are you setting $OLDPWD manually? Also, you can use ${PWD%/*} instead of $(dirname "$PWD") and ${OLDPWD##*/} instead of $(basename "$OLDPWD"). Also, quote your variables; you can also use...

        Why are you setting $OLDPWD manually? Also, you can use ${PWD%/*} instead of $(dirname "$PWD") and ${OLDPWD##*/} instead of $(basename "$OLDPWD"). Also, quote your variables; you can also use double brackets instead of single ones so you won't have to quote the variable in the test. And why did you use an if statement instead of just &&? You could actually probably replace that whole loop with a find one-liner. Finally, head/tail's -<number> is obsolete syntax and is discouraged.

        I know that you weren't too serious about writing this; just encouraging good form. :)

        1 vote
        1. [3]
          unknown user
          Link Parent
          Thanks! I've tried learning those substitutions many times, but I keep forgetting them, and I'm not sure if they're in POSIX (I keep my bashrc and .profile mostly compatible with POSIX sh so that...

          Thanks! I've tried learning those substitutions many times, but I keep forgetting them, and I'm not sure if they're in POSIX (I keep my bashrc and .profile mostly compatible with POSIX sh so that I don't need different files for different shells, a habit from when I used FreeBSD).

          $OLDPWD wasn't being set for some reason, that's why I set it manually. But I did a typo or something I guess.

          New aliases:

          alias right='cd "$( find -L ${PWD%/*}/ -maxdepth 1 -type d -not -name \".*\" | sort | grep -A 1 ../${PWD##*/} | tail -n 1 )"'
          alias left='cd "$( find -L ${PWD%/*}/ -maxdepth 1 -type d -not -name \".*\" | sort | grep -B 1 ../${PWD##*/} | head -n 1 )"'
          
          1. [2]
            Crestwave
            Link Parent
            Note that the quoting around the command substitution doesn't apply to the commands inside; those quotes don't need to be escaped unless there's another reason I'm missing, and the variables...

            Note that the quoting around the command substitution doesn't apply to the commands inside; those quotes don't need to be escaped unless there's another reason I'm missing, and the variables should probably be quoted.

            1. unknown user
              Link Parent
              Thanks!

              Thanks!

    2. ali
      Link Parent
      That's pretty handy, I'll copy that. Currently I open the folder and use a shortcut to open the Terminal in that folder

      That's pretty handy, I'll copy that. Currently I open the folder and use a shortcut to open the Terminal in that folder

      2 votes
    3. Ordinator
      Link Parent
      I do alias ..=cd .. alias ...=cd ... etc for 5 or so levels

      I do

      alias ..=cd ..
      alias ...=cd ...
      

      etc for 5 or so levels

      1 vote
  12. [3]
    crdpa
    Link
    These ones: alias xi='xbps-install' alias xr='xbps-remove' alias xq='xbps-query -Rs'

    These ones:

    alias xi='xbps-install'
    alias xr='xbps-remove'
    alias xq='xbps-query -Rs'
    
    4 votes
    1. acdw
      Link Parent
      OMG same 😂 I actually just uninstalled Void, but I might go back. Manjaro KDE is too fancy in some ways, and I'm missing the slimness of Void. Maybe if I reinstall it I'll put it together better ..

      OMG same 😂

      I actually just uninstalled Void, but I might go back. Manjaro KDE is too fancy in some ways, and I'm missing the slimness of Void. Maybe if I reinstall it I'll put it together better ..

      3 votes
    2. yama
      Link Parent
      I just installed Void Linux and the xbps-* commands are too lengthy to type out every time... Somebody did create a wrapper for those commands: https://github.com/netzverweigerer/vpm. So instead...

      I just installed Void Linux and the xbps-* commands are too lengthy to type out every time...

      Somebody did create a wrapper for those commands: https://github.com/netzverweigerer/vpm. So instead of typing xbps-* you can just type vpm * which IMO is more intuitive.

      1 vote
  13. [3]
    unknown user
    (edited )
    Link
    I have this couple for job control: f () { fg %$@ } b () { bg %$@ } alias j=jobs With these I type j, f, b, f 1 and b 1 instead of jobs, fg, bg, fg %1 and bg %1. These are one of the most...

    I have this couple for job control:

    f () {
    	fg %$@
    }
    b () {
    	bg %$@
    }
    alias j=jobs
    

    With these I type j, f, b, f 1 and b 1 instead of jobs, fg, bg, fg %1 and bg %1. These are one of the most frequented ones.

    I also have alias sudo="sudo --preserve-env" which is convenient. With this sudo uses my env.

    Lastly, these below are my Debian aliases which I use often:

    alias deps='apt-cache depends --no-recommends --no-breaks --no-suggests --no-conflicts --no-enhances --no-replaces --recurse'
    alias fresh='sudo apt-get update && (apt list --upgradable | less)'
    alias haz="dpkg-query -l"
    alias has="apt-cache search"
    alias show="apt-cache show"
    

    Edit: replace pg with less, it is another alias I have for $PAGER. Sorry for the inconvenience.

    3 votes
    1. [2]
      unknown user
      Link Parent
      What's pg? command-not-found doesn't seem to know about it.
      alias fresh='sudo apt-get update && (apt list --upgradable | pg)'
      

      What's pg? command-not-found doesn't seem to know about it.

      2 votes
      1. unknown user
        Link Parent
        Whoops, sorry. It is an alias for $PAGER, you can replace it with less or more. pg itself is, where available, a historical pager used before more. I don't know which package would have it tho, I...

        Whoops, sorry. It is an alias for $PAGER, you can replace it with less or more.

        pg itself is, where available, a historical pager used before more. I don't know which package would have it tho, I think I encountered it on FreeBSD.

        3 votes
  14. [2]
    oscillot
    Link
    I make extensive use of aliases, and after all my aliases are defined I have this: # NO ALIASES BELOW ME PLEASE. UNLESS THEY ARE SUPER DUPER SECRET! # cut and tr for formatting # sed to push...

    I make extensive use of aliases, and after all my aliases are defined I have this:

    # NO ALIASES BELOW ME PLEASE. UNLESS THEY ARE SUPER DUPER SECRET!
    # cut and tr for formatting
    # sed to push command continuations indented on to new lines
    # ack for simple colors
    function aliases() {
    alias | cut -d' ' -f2- | tr "='" "\t" | sort | sed -e $'s/&&/&\\\n\\\t\\\t  /g' | sed -e $'s/;/;\\\n\\\t\\\t  /g' | ack -i "^[\S]*" --color-match=cyan --passthru
    }
    aliases
    

    Which spits all my aliases out for me when I start a new login shell or call the aliases function. Especially useful when I have just added a new alias and haven't committed it to memory yet.

    Example (restart docker-machine and bring up an arbitrary container tree from a compose file in my localdev directory, then return to whatever directory I was just in):

    dkr		pushd . &&
    		   cd ~/dev/localdev &&
    		   docker-machine stop;
    		   docker-machine start &&
    		   eval $(docker-machine env) &&
                        docker-compose up $1 -d
    		   popd
    

    The alias gets syntax highlighted to cyan and multiple commands (ending in ; or && stack although it's a very naive implementation.

    The function is not pretty and it doesn't scale well to very large aliases but I like it all the same.

    This is on macos so there may be some adjustments needed for Linux, I am not sure.

    3 votes
    1. jwong
      Link Parent
      Is there a way to have this only show aliases defined in your .rc file? I have a bunch from oh-my-zsh that I don't even use, so the list of arises is way longer than is practical to read through.

      Is there a way to have this only show aliases defined in your .rc file? I have a bunch from oh-my-zsh that I don't even use, so the list of arises is way longer than is practical to read through.

  15. cadentius_aurelius
    Link
    Didnt write it in .bashrc because I wanted to be able to invoke it in other scripts, but recently /usr/local/bin/send-to-vms has been a big help in my experiments with virtualization: #! /bin/bash...

    Didnt write it in .bashrc because I wanted to be able to invoke it in other scripts, but recently /usr/local/bin/send-to-vms has been a big help in my experiments with virtualization:

    #! /bin/bash
    
    cmd=$1
    name=$2
    
    if [$name == ""]; then
            name="root"
    fi
    
    for iter in {32..39}; do
            echo "COMMAND SENDING TO $name@192.168.0.$iter:22"
            ssh -o VisualHostKey=no $name@192.168.0.$iter $cmd
    done
    

    Been using it to update all my VMs at once, or to write a file to all of them. Im sure theres something dedicated to this in libvirt, but thats boring :D

    2 votes
  16. [9]
    Soptik
    Link
    Not really crucial, but it feels nice to have it. I use couple aliases that setup my workflow. alias web="cd ~/Programming/Dart/Web/MyCurrentProject; code .; git pull" alias fiks="cd...

    Not really crucial, but it feels nice to have it.

    I use couple aliases that setup my workflow.

    alias web="cd ~/Programming/Dart/Web/MyCurrentProject; code .; git pull"
    
    alias fiks="cd ~/Programming/FIKS; code .; firefox https://fiks.fit.cvut.cz"
    
    alias dnd="xdg-open ~/Documents/DnD.pdf; xdg-open ~/Documents/Griki.odg"
    
    alias pi="ssh pi@192.168.1.2"
    

    Now, I just have to figure out how to execute commands as root on startup without the need to type my password. When I want to change brightness with i3, I register keyboard keys and run my script that writes directly into some random file, because there is no other way how to make it work. The problem is that the file is root read/write only, so I have to have another script which chmods the file so my brightness changing script can write into it. The problem is that I have to type my password again to run the chmod script, which is annoying.

    2 votes
    1. [7]
      unknown user
      Link Parent
      Whereabouts is the file located? There's probably a better solution then chmodding it on every boot. e.g. if it's in /dev, then you can probably write a udev rule that will set the permissions up...

      The problem is that the file is root read/write only, so I have to have another script which chmods the file so my brightness changing script can write into it. The problem is that I have to type my password again to run the chmod script, which is annoying.

      Whereabouts is the file located? There's probably a better solution then chmodding it on every boot. e.g. if it's in /dev, then you can probably write a udev rule that will set the permissions up automatically.

      2 votes
      1. [6]
        Soptik
        Link Parent
        It's /sys/class/backlight/intel_backlight/brightness. I thought about setting up cron to run at reboot and chmod the file, which should work, but I'm not sure I like the solution. I wonder why is...

        It's /sys/class/backlight/intel_backlight/brightness. I thought about setting up cron to run at reboot and chmod the file, which should work, but I'm not sure I like the solution.

        I wonder why is root even needed to change this file, gnome can do it without root. I tried some packages that would allow me to change the brightness without messing with the file, but none worked.

        3 votes
        1. [5]
          Emerald_Knight
          Link Parent
          Uh... it sounds like you're trying to change the permissions on the file at startup to be writable by the user. This isn't what you want to do. This is very not Linux-like. You should be setting...

          Uh... it sounds like you're trying to change the permissions on the file at startup to be writable by the user. This isn't what you want to do. This is very not Linux-like. You should be setting up a script to be run as root on startup, which would allow the file modifications to run without having to perform a chmod.

          What distro are you running? Depending on which distro and which version, there should be a far more elegant solution to this problem that is well-supported and generally the officially recommended approach.

          2 votes
          1. [4]
            Soptik
            Link Parent
            I use Ubuntu 18.10, so any kind of community support is more than unlikely. Would you recommend me something to learn? I can probably find how to run script as root on startup, but I have no idea...

            I use Ubuntu 18.10, so any kind of community support is more than unlikely.

            Would you recommend me something to learn? I can probably find how to run script as root on startup, but I have no idea what should be done next.

            1 vote
            1. [3]
              Emerald_Knight
              Link Parent
              Regarding running as root, consider taking a look at this thread. Specifically, I would recommend looking at this answer or this one. Please note that it's absolutely essential in the case of...

              Regarding running as root, consider taking a look at this thread. Specifically, I would recommend looking at this answer or this one. Please note that it's absolutely essential in the case of using a crontab to set it as root via sudo crontab -e, otherwise you will run into the same permissions issues.

              As for what to do from there, I honestly don't know. This is why I'm asking for details about your particular problem. I have only the vaguest idea of what it is you're trying to accomplish. I literally cannot help you any further without additional details, otherwise I'll just be sending you random resources to look at that may or may not even be relevant to actually solving your problem. In order to receive even a modicum of guidance, you'll first need to describe exactly what it is that you're trying to accomplish and how you're trying to accomplish it.

              If you don't want a straight-up answer so you can figure it out on your own, then that's fine. But details are still needed to assess what would need to be done in the first place and whether or not you're on the right track so I can determine what direction to point you in.

              2 votes
              1. [2]
                Soptik
                Link Parent
                Thank you. I don't really need some tutorial or step-by-step solution - it works for now, even with the annoying chmod step (which could be automated with the links you sent). And I think...

                Thank you. I don't really need some tutorial or step-by-step solution - it works for now, even with the annoying chmod step (which could be automated with the links you sent). And I think kiddico's solution might work, as it looks like he had the same problem.

                So, the problem is: I want to set screen brightness. The usual tools (eg xbacklight) didn't work (but light from kiddico's comment might). So I found a way how to set it by writing to /sys file. But I have to be root to do it. So I'm now more interested in how is it done without root, how does gnome and other tools do it, so when I encounter simmilar problem, I'll be able to solve it, and especially know how did the solution work.

                I searched and maybe making some udev rule should work? I'll try it as I get to my computer. As I understand it, udev rules should somehow manage devices, so it seems to make sence.

                1 vote
                1. Emerald_Knight
                  Link Parent
                  Sorry for the delay. I've been a bit busy. Hitting udev would probably be the way to go, so you're likely on the right track. You might take a look at this Arch manual page regarding backlight...

                  Sorry for the delay. I've been a bit busy.

                  Hitting udev would probably be the way to go, so you're likely on the right track. You might take a look at this Arch manual page regarding backlight configuration management. They even touch on intel_backlight at some point, it looks like. Please note the following snippet:

                  By default, only root can change the brightness by this method. To allow users in the video group to change the brightness, a udev rule such as the following can be used:

                  /etc/udev/rules.d/backlight.rules

                  ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="acpi_video0", RUN+="/bin/chgrp video /sys/class/backlight/%k/brightness"
                  ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="acpi_video0", RUN+="/bin/chmod g+w /sys/class/backlight/%k/brightness"

                  You'll have to modify it to hit intel_backlight instead, which might look something like this:

                  ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="intel_backlight", RUN+="/bin/chgrp video /sys/class/backlight/%k/brightness"
                  ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="intel_backlight", RUN+="/bin/chmod g+w /sys/class/backlight/%k/brightness"
                  

                  You'll ultimately have to dig around a bit more to determine whether or not this is enough to suit your needs and, if not, which changes you'll need to make to get it working, but it should at least get you pretty close :)

    2. kiddico
      Link Parent
      Hey, I used to have tons of problems on my thinkpad with backlight controls and i3. I started using light. An update broke my original setup that just used xbacklight. I had to do what you're...

      Hey, I used to have tons of problems on my thinkpad with backlight controls and i3. I started using light. An update broke my original setup that just used xbacklight. I had to do what you're doing (and change a file's value) until someone pointed me towards (the) light. It's not horribly hard to setup, here's all I had to do to make the inc/dec brightness keys work. (after installing light that is)

      1 vote
  17. [2]
    Luna
    (edited )
    Link
    When I was working full time, I had a fair amount of stuff in my zshrc, but it was mainly to speed up things like kubectl commands and pruning docker images. My PC has Windows on it (I want to...

    When I was working full time, I had a fair amount of stuff in my zshrc, but it was mainly to speed up things like kubectl commands and pruning docker images. My PC has Windows on it (I want to install Linux Mint but I can't get KVM GPU passthrough working), so my WSL zshrc is pretty simple, these are the only aliases I have:

    alias eztar="tar -czvf" # I have to tar.gz assignments for my parallel computing class
    alias l="ls -la" # because I always end up needing -la
    alias vi="nvim" # I use both Vim and NeoVim, and I alias vi to NeoVim since I use it more than Vim
    alias rserver="bundler exec rails s -b 'ssl://127.0.0.1:3000?key=config/ssl/<domain>.key&cert=config/ssl/<domain>.crt'" # I have to have HTTPS for U2F in my rails apps, so I have a cert I load when I start the server
    alias rreload="bundle exec rake db:drop && bundle exec rake db:create && bundle exec rake db:migrate && bundle exec rake db:seed" # because I'm too lazy to type this stuff out by hand
    alias rquickload="bundle exec rake db:drop && bundle exec rake db:create && bundle exec rake db:schema:load && bundle exec rake db:seed"
    

    (I also have aliases for my university's HPC clusters, but those are just SSH.)

    Edit: I almost forgot:

    alias gccp="g++ -std=c++11 -pedantic-errors -Wall $1 $2 $2" # for my parallel computing class
    
    2 votes
    1. Emerald_Knight
      Link Parent
      Oh, fuck. Rails. I'm going to go on a tangent for a moment and tell a little story about my own little hell. During my own university studies, one of the required courses for my chosen "track" (a...

      Oh, fuck. Rails. I'm going to go on a tangent for a moment and tell a little story about my own little hell.

      During my own university studies, one of the required courses for my chosen "track" (a set of courses defining your specific focus, e.g. security or networking) was an introduction to software engineering principles. This was an upper-division course that focused on issues ranging from software development lifecycles, to project management, and in a later iteration of the course, even working on joint projects with teams from other countries (a story for another time). For this particular course, though, we focused mostly on doing a couple of "large" (by university project standards) software projects spanning multiple weeks in small teams.

      Well, my team was... "special". They decided, for some unknown reason--possibly the sadistic whisperings of Satan himself influencing them--that we should all use a language, framework, and tech stack that none of us had any experience with whatsoever. That was Rails. None of us--not a single one of us--even knew what the hell the difference between a "GET" and a "POST" request was... and they decided we should use Rails. Super.

      Oh, but here's the best part: I was the one who ended up blowing through the documentation, doing hours of research, and prototyping basic proof of concept implementations just so I could get the others on board with how Rails even worked. If I hadn't done that leg work, we probably would've still been stuck trying to figure out the most basic shit half way through the project timeline. We had to not only figure out how to work with Rails, but how to implement behavior that we'd never had to implement before in any project of any type. Things like geocoding, array serialization and de-serialization for storing in database columns, handling file uploads, and various other little pieces that would otherwise be pretty simple if literally any of us had ever worked with web development for anything more than basic JavaScript and DOM manipulation.

      And since the guy who was in charge of deploying the app onto a server so we could actually demo it couldn't figure out how to get things working, we ended up running it from a cloud IDE... which had a tendency to crash randomly when we wanted to test a critical piece of functionality. Including during our end-of-term presentation. So the entire time it was seriously the blind leading the blind through a freakin' minefield and somehow, by the grace of some merciful deity, we were given a passing grade in the end.

      It was truly a nightmare and I'm amazed that I never developed even a slight aversion to web development as a result.

      Kind of a long tangent, but seeing those Rails aliases brought that little bit of academic trauma out of physical memory and right into my L1 cache.

      3 votes
  18. vSanjo
    Link
    Mine's simple! My monitor setup demands a restart after a while - the 2017 Macbook Pro just doesn't agree with my hardware - so I tend to have a simple startup command that runs open with a few...

    Mine's simple!

    My monitor setup demands a restart after a while - the 2017 Macbook Pro just doesn't agree with my hardware - so I tend to have a simple startup command that runs open with a few apps, bubu that I believe oh-my-zsh installs (that updates Homebrew fully) and then ends with opening a nice clean tmux for me to begin my day.

    1 vote
  19. pleure
    Link
    export HISTCONTROL=ignoreboth:erasedups I often find myself, for example, running make over and over again, so if I don't have this set and want to go to a previous command it takes forever

    export HISTCONTROL=ignoreboth:erasedups

    I often find myself, for example, running make over and over again, so if I don't have this set and want to go to a previous command it takes forever

    1 vote
  20. SUD0
    Link
    setxkbmap -option ctrl:swapcaps Caps lock is just such a useless key in such an important position on a keyboard.

    setxkbmap -option ctrl:swapcaps

    Caps lock is just such a useless key in such an important position on a keyboard.

    1 vote
  21. IvyMike
    Link
    As a recent windows user: alias start=xdg-open

    As a recent windows user:
    alias start=xdg-open

    1 vote
  22. yama
    Link
    Not really aliases or functions, but the two for me are: Reverse history search bind '"\e[A":history-search-backward' bind '"\e[B":history-search-forward' Emacs bindings (with Caps Lock remapped...

    Not really aliases or functions, but the two for me are:

    • Reverse history search
    bind '"\e[A":history-search-backward'
    bind '"\e[B":history-search-forward'
    
    • Emacs bindings (with Caps Lock remapped to Ctrl)

    Both of these have been my secret sauce for flying in the shell.

    1 vote
  23. rts
    Link
    function noagenda.download() { wget $(echo $(curl -s http://www.noagendashow.com/ | grep "to the mp3 file") | cut -d'"' -f4) } Downloads the latest episode of the No Agenda podcast. Could be...
    function noagenda.download() {
      wget $(echo $(curl -s http://www.noagendashow.com/ | grep "to the mp3 file") | cut -d'"' -f4)
    }
    

    Downloads the latest episode of the No Agenda podcast. Could be prettier, but a critical part of my Thursday and Sunday routine :)

  24. brandons
    Link
    I have some there are maybe more interesting or powerful, but these probably save me 1-5 days per year: alias gb="git branch" alias gc="git checkout" alias gp="git pull" alias gs="git status"...

    I have some there are maybe more interesting or powerful, but these probably save me 1-5 days per year:

    alias gb="git branch"
    alias gc="git checkout"
    alias gp="git pull"
    alias gs="git status"
    alias gfu="git fetch upstream"
    
  25. mat
    Link
    lr () { ssh mat@192.168.1.66 ${1+"$@"}; } Nothing too special, if I do lr on it's own it connects to my home server. But if I do lr full_backup.sh It runs the command 'full_backup.sh' on my home...

    lr () { ssh mat@192.168.1.66 ${1+"$@"}; }

    Nothing too special, if I do

    lr

    on it's own it connects to my home server. But if I do

    lr full_backup.sh

    It runs the command 'full_backup.sh' on my home server and then disconnects. Which is handy if I do just want to run one command remotely, which I quite often do. I have a bunch of two letter aliases for my most used remote machines.

  26. knocklessmonster
    Link
    if [ `$tty` == "/dev/tty1" ] then exec ~/.bin/start.sh fi which calls start.sh, which has some variation of #!/usr/bin/env bash echo -e "Choose a session:\ \n 1) XFCE\ \n 2) i3\ \n" read -p "Which...
    if [  `$tty` == "/dev/tty1" ] then
    exec ~/.bin/start.sh
    fi
    

    which calls start.sh, which has some variation of

    #!/usr/bin/env bash
    echo -e "Choose a session:\
    	\n 1) XFCE\
    	\n 2) i3\
    	\n"
    read -p "Which session? " REPLY
    echo
    case "$REPLY" in
    	1 ) startx /usr/bin/mate-session;;
    	2 ) startx /usr/bin/i3 ;;
    esac
    

    It's basically a hacky session manager I cobbled together based on an example from the Arch wiki (that used DISPLAY and XDG_VTNR), but I've been experimenting with other distros, and wanted a more generic solution that works for my single-monitor computers. It helps with the minor instability nvidia brings to my Arch desktop.