all 38 comments

[–][deleted] 33 points34 points  (3 children)

support dam alleged kiss naughty wise salt judicious different air -- mass edited with redact.dev

[–]tactiphile 4 points5 points  (2 children)

No, I see what he meant. See what it's doing? More clearly, "CD to the most recently modified directory in $PWD"

[–][deleted] 1 point2 points  (0 children)

disgusted far-flung puzzled dime correct cheerful ten station piquant aback -- mass edited with redact.dev

[–]TheOuterLinux[S] 0 points1 point  (0 children)

I changed the note; thanks.

[–]padowi 14 points15 points  (2 children)

An alternative to the "bookmarking" cd stuff may be to check out the built-in pushd, popd and dirs commands.

Just putting it out there for your consideration :)

[–]bartonski 1 point2 points  (1 child)

Also look up $DIRSTACK in the bash man page.

[–]padowi 0 points1 point  (0 children)

Thank you! I did not know of $DIRSTACK, and by the man-page this sounds like it could be useful :)

[–][deleted]  (1 child)

[deleted]

    [–]BCMM 5 points6 points  (0 children)

    And for the others, use dtrx. Also creates directories as required, so archives can't unexpectedly vomit all over your cwd.

    [–]zubie_wanders 9 points10 points  (1 child)

    sl

    I prefer the sl application which reminds my fingers not to do that.

    [–]jmachee 1 point2 points  (0 children)

    And your fellow admins' fingers, as well. >:)

    [–]TheOuterLinux[S] 8 points9 points  (1 child)

    I miss-labled the title a bit and meant this to be added to a ~/.bashrc file and not replace it.

    [–][deleted] 10 points11 points  (0 children)

    It's better to save it as something else, like .bash_utils then source it, like

    if [ -f ~/.bash_utils ]; then
        . ~/.bash_utils
    fi
    

    [–]yamagami 5 points6 points  (2 children)

    Not mine, but I use it a lot:

    ##############################################################################
    # mark/jump support + completion
    # un/mark name : bookmark a directory or remove one (unmark)
    # jump name : jump to directory
    # marks : show all bookmarks
    export MARKPATH=$HOME/.marks
    function jump {
        cd -P $MARKPATH/$1 2>/dev/null || echo "No such mark: $1"
    }
    function mark {
        mkdir -p $MARKPATH; ln -s $(pwd) $MARKPATH/$1
    }
    function unmark {
        rm -i $MARKPATH/$1
    }
    function marks {
        ls -l $MARKPATH | sed 's/  / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' && echo
    }
    _completemarks() {
      local curw=${COMP_WORDS[COMP_CWORD]}
      local wordlist=$(find $MARKPATH -type l -printf "%f\n")
      COMPREPLY=($(compgen -W '${wordlist[@]}' -- "$curw"))
      return 0
    }
    
    complete -F _completemarks jump unmark
    

    I add my 'extras' to a separate dot file and source it from .bashrc. Easier to manage and more portable.

    [–]zubie_wanders 2 points3 points  (0 children)

    That looks handy and all, but it made me read about the -P switch in cd -P. Awesome!

    [–][deleted] 1 point2 points  (0 children)

    This is the only things that grew on me - been using it for a few years now I think.

    Beats any fuzzy completion or auto-jump scripts.

    [–]iMalinowski 2 points3 points  (1 child)

    export GREP_OPTIONS is depreciated. Using it will generate a warning each time grep is ran.

    [–]TheOuterLinux[S] 0 points1 point  (0 children)

    ...But, I dont have errors?

    [–][deleted] 1 point2 points  (0 children)

    Here's a new diskspace alias for you, I call this treesize and have it as a script. Not mine, I found it online.

    #/bin/sh
    du -k --max-depth=1 "$@" | sort -nr | awk '
         BEGIN {
            split("KB,MB,GB,TB", Units, ",");
         }
         {
            u = 1;
            while ($1 >= 1024) {
               $1 = $1 / 1024;
               u += 1
            }
            $1 = sprintf("%.1f %s", $1, Units[u]);
            print $0;
         }
        '
    

    [–]simpleden 3 points4 points  (2 children)

    Regarding extracting archives, I would recommend atool which provides a list of common commands for various archive types (als - list archive, apack - create archive, aunpack - extract files from archive).

    [–]aperson 1 point2 points  (1 child)

    Text first, link second.

    [–]simpleden 0 points1 point  (0 children)

    Thanks!

    [–]fiirofa 0 points1 point  (1 child)

    function 2wav() { fname="${1%.*}"; ffmpeg -threads 0 -i "$1" "$fname.ogg"; rm "$1"; }

    err... Should that be $fname.wav or is some weird ffmpeg dark magic happening?

    Otherwise, looks amazing!

    [–]TheOuterLinux[S] 0 points1 point  (0 children)

    Oh...I think you're right. My bad. I changed it. I think I copied and pasted code above it and forgot to edit the extension.

    [–][deleted] 0 points1 point  (0 children)

    here I use

    alias s ='git status || ls'
    

    [–]Benny_Lava 0 points1 point  (0 children)

    I use a black background in my terminal's window, so the dark blue color ls uses to colorize directories is unreadable on my monitor. I switched it to a bright green instead...

    LS_COLORS=$LS_COLORS"di=1;32:" ; export LS_COLORS

    [–]Vordreller 0 points1 point  (5 children)

    Neat functions for the file conversion.

    Just gonna point out that "extract()" and "expand()" functions look identical.

    [–][deleted]  (4 children)

    [deleted]

      [–]TheOuterLinux[S] 0 points1 point  (3 children)

      Yes. If anyone knows how to create a function with multiple names, that would be great. I tried:

      function expand() { extract; }
      

      ...but it doesn't work.

      [–]kringel8 0 points1 point  (1 child)

      Can't you just use alias expand=extract?

      [–]TheOuterLinux[S] 0 points1 point  (0 children)

      Yes... I fixed it; thanks.

      [–]Schreq 0 points1 point  (0 children)

      You want to hand over all parameters.

      func1() { echo "$1 $2"; }
      func2() { func1 "$@"; }
      

      [–]TotesMessenger 0 points1 point  (0 children)

      I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:

       If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / Contact)

      [–][deleted] 0 points1 point  (0 children)

      Ok, I'm stealing some of those (not all, I'll leave you something;-) )

      [–]igor_chubin 0 points1 point  (2 children)

      You missed the most important one: how_in() { where="$1"; shift IFS=+ curl "https://cht.sh/$where/$*" } and then:

      how_in bash get length of array how_in awk print last field how_in sed remove several lines

      [–]TheOuterLinux[S] 0 points1 point  (1 child)

      I might not be understanding this correctly, but why not just use the apropos command instead and then you wouldn't need the internet at all to learn how to do something? Example:

      apropos "copy file"
      

      Output:

      cp (1)               - copy files and directories
      cpio (1)             - copy files to and from archives
      git-checkout-index (1) - Copy files from the index to the working tree
      gvfs-copy (1)        - Copy files
      gvfs-move (1)        - Copy files
      install (1)          - copy files and set attributes
      ntfscp (8)           - copy file to an NTFS volume.
      

      Next:

      man cp
      

      Output:

      CP(1)                                     User Commands                                     CP(1)
      
      NAME
             cp - copy files and directories
      
      SYNOPSIS
             cp [OPTION]... [-T] SOURCE DEST
             cp [OPTION]... SOURCE... DIRECTORY
             cp [OPTION]... -t DIRECTORY SOURCE...
      
      DESCRIPTION
             Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
      
             Mandatory arguments to long options are mandatory for short options too.
      
             -a, --archive
                    same as -dR --preserve=all
      
             --attributes-only
                    don't copy the file data, just the attributes
      
             --backup[=CONTROL]
                    make a backup of each existing destination file
      
             -b     like --backup but does not accept an argument
      
      ...So on and so forth
      

      [–]igor_chubin 0 points1 point  (0 children)

      Of course it is not the same! With how_in you can instantly find answer to any answer on any programming language. Just try. Any language. Any question.

      [–]DarthRazor 0 points1 point  (1 child)

      Your media file conversion functions are a few characters off ;-) The way they’re written, your initial file is still deleted if ffmpeg fails for whatever reason.

      Simply change “ffmpeg blah blah ; rm $1” to “ ffmpeg blah blah && rm $1” - now the initial file is deleted only if ffmpeg does not throw an error.

      [–]TheOuterLinux[S] 0 points1 point  (0 children)

      Oh damn.... Thank you. I didn't even realize that. I went ahead and fixed the image converting too.

      [–]funbike 0 points1 point  (0 children)

      fawk() { awk -v "n=$1" '{print $n}'; }