Yes, it's called
export HISTSIZE=10000000
Yes, it's called
export HISTSIZE=10000000
And remembering to back up the history, ask me how I know
I have lots of scripts and aliases since I run a very mininal setup.
The aliases are automatically set when I start a new shell and I have a shortcut command to cat the alias file so I can quickly view what aliases and functions I have saved.
I also have a folder that contains all my notes and scripts. It's all organized and it acts as a staging area before I move any scripts to the proper location or device.
I found a hobby in writing scripts. I've been spending a lot of time writing my own backup system that uses rsync and it's nearing completion which I'm excited about. It's been something I've been working building on and off since the new year began.
Every machine I own has a scripts folder in the users home. It contains anything and everything, from starting and stopping services to changing settings, updating my boot order, literally anything I don't use often enough to alias, but know I will use at some point.
Not overly related to your question, but for #3 you should put your template .desktop file into the ~/Templates folder (create it if it doesn’t exist) and then you can make new ones with the right click -> Create New submenu in your file manager
This works for anything btw, not specific to .desktop files
Oooh ty that makes a lot of sense. I was unaware of that functionality.
My go to is sticking what I can in my profile and making aliased commands for them all. Don't have many for Linux quite yet but my PS profile is lapsed with dozens of these.
This should be the next step for me. When you do aliased commands, can they take arguments? Like to download a playlist with yt-dlp, could i do download-playlist [URL]?
When you do aliased commands, can they take arguments? Like to download a playlist with yt-dlp, could i do download-playlist [URL]?
They don't take arguments in the sense that functions do but in bash at least they are passed on as part of the expanded string. Pasted from bash:
alias argtest='echo arg is'
argtest foo
arg is foo
So yes you could alias your yt-dlp commands and invoke the alias with the URL.
Yeah. This is my alias to download music from YouTube alias yt-dmus='yt-dlp -x --audio-format opus "$@"'
alias e='echo "${@}"' Wait a second, Bash does not process arguments in alias. This is an incredible trick new to me! All the years I was writing a function to accomplish that. I wonder if there is any drawback to this technique.
Not that I know of
Aliases themselves do not take arguments. You can write Bash function for that case. Here is a "simple" example. I leave the comments there explaining the command too:
treegrep
treegrep() {
# grep:
# --recursive like --directories=recurse
# --files-with-match print only names of FILEs with selected lines
# tree:
# --fromfile Reads paths from files (.=stdin)
# -F Appends '/', '=', '*', '@', '|' or '>' as per ls -F.
grep --recursive --files-with-match "${@}" |
tree --fromfile -F
}
yesno
You can also set variables to be local to the function, meaning they do not leak to outside or do not get confused with variables from outside the function:
# usage: yesno [prompt]
# example:
# yesno && echo yes
# yesno Continue? && echo yes || echo no
yesno() {
local prompt
local answer
if [[ "${#}" -gt 0 ]]; then
prompt="${*} "
fi
read -rp "${prompt}[y/n]: " answer
case "${answer}" in
[Yy0]*) return 0 ;;
[Nn1]*) return 1 ;;
*) return 2 ;;
esac
}
This is what I ended up doing, and it works great. I knew about aliases, but didn't really use them at all - I didn't know about bash functions though.
So now I have a few functions in .bashrc for short things and am just aliasing shell scripts for easy access to more complex tbings I don't want cluttering the file
I do write scripts and commands (and Bash aliases or functions) all the time. The scripts live in ~/.local/bin and are executable like any other program, as that directory is in my PATH variable. I have a projects directory where I archive them, and some of them are uploaded to my Github account. Some of them are later rewritten in Python and get a life on its own.
?)Besides my more simple scripts and aliases and functions.
6. system
update and all updates:
alias update='eos-update --yay'
alias updates='eos-update --yay ;
flatpak update ;
flatpak uninstall --unused ;
rustup self update ;
rustup update'
7. Or a recent script to convert files to mp3 format:
tomp3
#!/usr/bin/env bash
for file in "${@}"; do
output="${file%.*}.mp3"
if [[ -f "${output}" ]]; then
continue
fi
ffmpeg -i "${file}" -b:a 320k "${output}"
done
That's so clever yet so simple, keep all the scripts in folder that's in PATH. I will deffo use that idea instead of a dedicated folder called scripts in my home folder.
I wonder if this could solve my Jellyfin format problems.
Usually have kind of staging public area, and after some refinements some scripts are moved to its own repository and can be installed using bash package manager. Not my own invention but contains not yet merged code that can install scripts from github or gitlab
Available scripts:
git <tab> and will expand to show available commandsI simply have my most used commands in history. I just need to remember the command start and its done. Yay fish!
But, I should start saving the commands in a file backup in case the command ever gets lost.
Heres my ~/.bin directory:
https://github.com/promitheas17j/dotfiles/tree/main/dot_bin
Hopefully thats what youre asking for.
My favourite ones are:
One that Im still working on but will for sure be my favourite once its done is parse_keybinds.sh and keybind_cheatsheet.sh, which go through some of the software I have and parse their config files to extract all the keybinds into a file with a specific format. The latter script then launches a rofi menu where I can fuzzy search keybinds based on software name and what I want to do but cant remember the binding for. So far Ive got sxhkd and lf, but I consider it a work in progress because I want to also parse neovim bindings, but sxhkd and lf are single file configs while neovim has bindings in multiple files spread across multiple subdirectories in its config directory.
I have a personal wiki instance hosted for that purpose. I collect knowlege in it, that I might need later and forget. Although I might not use dokuwiki, if I had so start the wiki again (would go to markdown).
I used to keep them all in my .bashrc, later I moved to keeping them in a .scripts folder in my home, then I add it to my $PATH.
Technically I could just make them all fish shell functions, but I figure it makes more sense to write regular bash (and have them no matter what shell I'm currently using) than the odd ball fish syntax no one really shares online.
Sorry, late to the party. I like to use variations of them for debugging:
red="$(tput setaf 1)"
#green="$(tput setaf 2)"
yellow="$(tput setaf 3)"
blue="$(tput setaf 4)"
reset="$(tput sgr0)"
messg() { printf '%-20s\t%s\n' "$1" "$2"; }
warn() { messg "${yellow}Warn${reset}:" "$1"; }
error() { messg "${red}Error:" "$1" >&2; [ -n "$2" ] && exit "$2"; } # complain to STDERR and exit if given code
debug() { [ -n "$debug" ] && messg "${blue}$1${reset}" "$2"; }
[ "$debug" = "verbose" ] && set -x
if [ -n "$debug" ]; then
alias rm='rm -v'
alias mv='mv -v'
alias mkdir='mkdir -v'
alias ln='ln -v'
fi
And those for config/state management:
get_state() { grep "$1" "$state_file" 2>/dev/null |cut -d':' -f2; }
set_state() { printf '%s:%s\n' "$1" "$2" >> "$state_file"; }
get_conf() { cut -d'#' -f1 "$config_file" |grep -- "$1" |cut -d"=" -f2- ; }
set_conf() {
#: gracefully sets config options
#: meaning: changes value if key exists, creates it if not
key="$1" value="$2" config="$config_file"
if grep -Eq "${key}=" "$config"
then sed -Ei "s/$key=.*/$key=$value/g" "$config"
else printf '%s=%s\n' "$key" "$value" >> "$config"
fi
}
And a few more:
isexec() { [ -x "$(command -v "$1" 2>/dev/null)" ]; }
contains() { case "$1" in *${2}*) return 0;; *) return 1;; esac; }
I selfhost ByteStash and then save anything I use frequently and reference it when I need it.
I have a .scripts folder in home with a bunch of things. Most of them are for backups, aka they just rsync a bunch of things from different places into one place on my backup drive. I also have one called get_trailers that I can run in my Radarr folder which takes the names of any movie folders in there and uses yt-dlp to search and grab the trailers from Youtube and puts them in the correct folders alongside the movie.
I was going give my joke answer about how I just made a bash script to mount all my hard drives to mnt/[directories 1-13], instead of just mounting it through F-Stab, but this is NOTHING compared to your examples...
For anything more complicated than an alias, I tend to suck it up and write a program. I used to keep launcher scripts in ~/bin but I've recently taken to creating package manager packages for them. I've learned how to do that with NixOS and Arch Linux and I peeked at the Debian documentation.
I use obsidian with the self hosted live sync plugin and have a couchdb instance setup on my homelab server. With external access via ssl certs (the only way to access couchdb outside a local network is to get real certs). Now I can hit my notes from all my devices and systems. While it's not 'scripts' exactly it contains a ton of documentation for things I do, plan to do and have done.
Also use it as a store house for links to various things that I intend to pull in and refactor for my own use later. Or links to other larger repositories (book of secret knowledge, etc), stuff I've made public on GitHub like rules.d tutorials for some keyboards with web configuration.
I think the only actual script I have on there is:
for f in *.mp3 *.m4a *.m4b *.opus; do
[ -e "$f" ] || continue
pre="${f%.*}"
mkdir -p "$pre"
mv "$f" "$pre/"
done
Made it for moving loose audiobook files into individual folders.
Tons they are all in Obsidian where the rest of my Brain lives
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.
Community icon by Alpár-Etele Méder, licensed under CC BY 3.0