this post was submitted on 28 Jun 2023
30 points (94.1% liked)

Linux

48145 readers
862 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

As a person raised by GUIs, an extra visual confirmation and an extra prompt is a nice touch. I also like when the system says "Oh, is that a directory? No problem, I'll give you the usual treatment." You know what I mean?

alias ls='ls --group-directories-first --color=auto -w 120'
alias ll='exa --group-directories-first -l'
alias la='ll -a'
alias lt='ll --tree'

alias cp='cp --recursive --interactive --verbose --reflink=always'
alias mv='mv --interactive --verbose'

# custom pwd
# - replace $HOME with ~
# - make everything before the last '/' green, and everything after white and bold
# - alias to p
alias pwd="pwd | sed 's:$HOME:~:' | sed -E 's:(.*/)([^/]+):\x1b[32m\1\x1b[0m\x1b[1m\2\x1b[0m:'"
alias p="pwd"

# custom cd.
# - prints the new directory after cd'ing.
cd () { 
    command cd "$@" && p;
}
alias c="cd"
alias '..'='c ..'
alias '...'='c ../..'

# For the '~' alias, we want to use the original cd because printing '~'
# again would be redundant.
alias '~'='command cd'

# custom rm.
# adds a '-r' flag only if there is a single argument and that argument
# is a directory.
# This is because I want the behavior of -I (interactive) to be the default,
# but I also want to have the -r flag available when I need it without being
# prompted for single files.
function rm () { 
  if [ $# -eq 1 ] && [ -d "$1" ]; then
    rm --verbose --interactive=once --recursive "$1";
  else
    rm --verbose --interactive=once "$@";
  fi;
}

# mkdir + cd (created as a function because they run on the current shell,
# which is what we want for cd)
mc () { 
  mkdir -p -- "$1" && cd -P -- "$1";
}
you are viewing a single comment's thread
view the rest of the comments
[–] sebastiancarlos@lemmy.sdf.org 1 points 1 year ago* (last edited 1 year ago) (1 children)

That's fair.

I don’t really want to be confirming every file in a recursive rm or cp or mv either

Ah but rm will only make you confirm if there are more than 3 files to be removed. And cp and mv only if there's risk of overwriting. And it's only one confirm per command, not per file.

[–] nous@programming.dev 5 points 1 year ago (1 children)

You must have a different version of rm then I do:

$ rm -i a
rm: remove regular empty file 'a'? y
$ rm -ir f
rm: descend into directory 'f'? y
rm: remove regular empty file 'f/a'? y
rm: remove regular empty file 'f/b'? y
rm: remove regular empty file 'f/c'? y
rm: remove regular empty file 'f/d'? y
rm: remove regular empty file 'f/e'? y
rm: remove directory 'f'? y

Never really had an issue with cp or mv overwriting files where I didnt mean to. Possibly because I don't default recursive on all the time. So they tend to error when accidentality copying folders. And I tend to tab complete paths to see what is in them. I also tend to use rsync for copying large directories rather than just cp when the directories might not be empty to start with.

[–] sebastiancarlos@lemmy.sdf.org 1 points 1 year ago* (last edited 1 year ago)

This should work:

$ rm -Ir f