Just noticed mine has gotten quite unwieldy and should probably be split into multiple files - but curious how big everyone else’s is!
(Mine’s 1304 lines!
)
Just noticed mine has gotten quite unwieldy and should probably be split into multiple files - but curious how big everyone else’s is!
(Mine’s 1304 lines!
)
$ wc -l .bashrc
290 .bashrc
About 130 of those lines are mostly default Ubuntu stuff.
I honestly thought it would be bigger than that…
split into multiple files… 1304 lines!
Dude, you have a problem.
Your rc is larger than my emacs config (without comments). Curious what is in it.
Mine is 285 including comments and a bit of junk I should delete. It’s config, very few aliases, and otherwise functions for my prompt as I don’t use ohmyzsh or any such thing. Also very curious why yours is so big ![]()
My rc is definitely in need of cleaning up, and I definitely have some unused (and commented out functions in it) but to give you an idea why it’s so big:
For example I have a lot of functions like this - which are longer than they might otherwise be because of the number of servers I administer:
upload_file() {
server=$3
if [ -z "$3" ]; then
scp -P (port number) $1 root@$FIRST_SERVER:$2
elif [[ $server == "second" ]]; then
scp -P (port number) $1 root@$SECOND_SERVER:$2
elif [[ $server == "third" ]]; then
scp -P (port number) $1 root@$THIRD_SERVER:$2
elif [[ $server == "fourth" ]]; then
scp -P (port number) $1 root@$FOURTH_SERVER:$2
elif [[ $server == "fifth" ]]; then
scp -P (port number) $1 root@$FIFTH_SERVER:$2
...
}
upload_file_from_desktop() {
server=$3
if [ -z "$3" ]; then
scp -P (port number) /Users/Aston/Desktop/$1 root@$FIRST_SERVER:$2
elif [[ $server == "second" ]]; then
scp -P (port number) /Users/Aston/Desktop/$1 root@$SECOND_SERVER:$2
elif [[ $server == "third" ]]; then
scp -P (port number) /Users/Aston/Desktop/$1 root@$THIRD_SERVER:$2
elif [[ $server == "fourth" ]]; then
scp -P (port number) /Users/Aston/Desktop/$1 root@$FOURTH_SERVER:$2
elif [[ $server == "fifth" ]]; then
scp -P (port number) /Users/Aston/Desktop/$1 root@$FIFTH_SERVER:$2
...
}
download_file() {
server=$2
if [ -z "$2" ]; then
scp -P (port number) root@$FIRST_SERVER:$1 /Users/Aston/Desktop
elif [[ $server == "second" ]]; then
scp -P (port number) root@$SECOND_SERVER:$1 /Users/Aston/Desktop
elif [[ $server == "third" ]]; then
scp -P (port number) root@$THIRD_SERVER:$1 /Users/Aston/Desktop
elif [[ $server == "fourth" ]]; then
scp -P (port number) root@$FOURTH_SERVER:$1 /Users/Aston/Desktop
elif [[ $server == "fifth" ]]; then
scp -P (port number) root@$FIFTH_SERVER:$1 /Users/Aston/Desktop
fi
}
upload_directory() {
server=$3
if [ -z "$3" ]; then
scp -P (port number) -r $1 root@$FIRST_SERVER:$2
elif [[ $server == "second" ]]; then
scp -P (port number) -r $1 root@$SECOND_SERVER:$2
elif [[ $server == "third" ]]; then
scp -P (port number) -r $1 root@$THIRD_SERVER:$2
elif [[ $server == "fourth" ]]; then
scp -P (port number) -r $1 root@$FOURTH_SERVER:$2
elif [[ $server == "fifth" ]]; then
scp -P (port number) -r $1 root@$FIFTH_SERVER:$2
...
}
upload_directory_contents() {
server=$3
if [ -z "$3" ]; then
scp -P (port number) -r $1/* root@$FIRST_SERVER:$2
elif [[ $server == "second" ]]; then
scp -P (port number) -r $1/* root@$SECOND_SERVER:$2
elif [[ $server == "third" ]]; then
scp -P (port number) -r $1/* root@$THIRD_SERVER:$2
elif [[ $server == "fourth" ]]; then
scp -P (port number) -r $1/* root@$FOURTH_SERVER:$2
elif [[ $server == "fifth" ]]; then
scp -P (port number) -r $1/* root@$FIFTH_SERVER:$2
...
}
upload_directory_from_desktop() {
server=$3
if [ -z "$3" ]; then
scp -P (port number) -r /Users/Aston/Desktop/$1 root@$FIRST_SERVER:$2
elif [[ $server == "second" ]]; then
scp -P (port number) -r /Users/Aston/Desktop/$1 root@$SECOND_SERVER:$2
elif [[ $server == "third" ]]; then
scp -P (port number) -r /Users/Aston/Desktop/$1 root@$THIRD_SERVER:$2
elif [[ $server == "fourth" ]]; then
scp -P (port number) -r /Users/Aston/Desktop/$1 root@$FOURTH_SERVER:$2
elif [[ $server == "fifth" ]]; then
scp -P (port number) -r /Users/Aston/Desktop/$1 root@$FIFTH_SERVER:$2
...
}
upload_directory_contents_from_desktop() {
server=$3
if [ -z "$3" ]; then
scp -P (port number) -r /Users/Aston/Desktop/$1/* root@$FIRST_SERVER:$2
elif [[ $server == "second" ]]; then
scp -P (port number) -r /Users/Aston/Desktop/$1/* root@$SECOND_SERVER:$2
elif [[ $server == "third" ]]; then
scp -P (port number) -r /Users/Aston/Desktop/$1/* root@$THIRD_SERVER:$2
elif [[ $server == "fourth" ]]; then
scp -P (port number) -r /Users/Aston/Desktop/$1/* root@$FOURTH_SERVER:$2
elif [[ $server == "fifth" ]]; then
scp -P (port number) -r /Users/Aston/Desktop/$1/* root@$FIFTH_SERVER:$2
...
}
download_directory() {
server=$2
if [ -z "$2" ]; then
scp -P (port number) -r root@$FIRST_SERVER:$1 /Users/Aston/Desktop
elif [[ $server == "second" ]]; then
scp -P (port number) -r root@$SECOND_SERVER:$1 /Users/Aston/Desktop
elif [[ $server == "third" ]]; then
scp -P (port number) -r root@$THIRD_SERVER:$1 /Users/Aston/Desktop
elif [[ $server == "fourth" ]]; then
scp -P (port number) -r root@$FOURTH_SERVER:$1 /Users/Aston/Desktop
elif [[ $server == "fifth" ]]; then
scp -P (port number) -r root@$FIFTH_SERVER:$1 /Users/Aston/Desktop
...
}
Quite a large portion of the file is actually made up of push functions, and while I have some general functions which can handle smaller more basic sites, with commands like:
push pragprog ef # push pragprog giveaway to this forum
push manning efs # push manning giveaway to erlangforums
push pragmaticstudio dt # push pragmaticstudio giveaway to Devtalk
push efs # push elixir forum sponsors site
etc
For bigger sites the push functions are more involved, as they need to: turn the site off (BRB page) build assets, upload files/assets, run migrations, check permissions, run seeds if given the appropriate flag, turn site back on, etc. So these get a function each (which I could call from the main push function).
And then I have some random functions like:
push_devtalk_coming_soon() {
upload_directory_contents /Users/Aston/Sites/devtalk/comingsoon/ /home/devtalk.com/public/
}
push_erlang_coming_soon() {
upload_directory_contents /Users/Aston/Sites/Erlang\ Forums/Comingsoon/ /home/hello.erlangforums.com/public/
}
xmas_graphics_up() {
scp -P (port number) -r /Users/Aston/Sites/site-name/site-name\ 2016/Christmas\ graphics/xmas-graphics/interface/* root@$FIRST_SERVER:/home/site-name/public/images/interface/
scp -P (port number) -r /Users/Aston/Sites/site-name2/Christmas\ graphics/xmas-graphics/interface/* root@$FIRST_SERVER:/home/site-name2/public/images/ovinterface/
scp -P (port number) -r /Users/Aston/Sites/site-name3/Christmas\ graphics/xmas-graphics/interface/* root@$FIRST_SERVER:/home/site-name3/public/images/interface/
...
}
xmas_graphics_down() {
scp -P (port number) -r /Users/Aston/Sites/site-name/site-name\ 2016/Christmas\ graphics/normal-graphics/interface/* root@$FIRST_SERVER:/home/site-name/public/images/interface/
scp -P (port number) -r /Users/Aston/Sites/site-name2/Christmas\ graphics/normal-graphics/interface/* root@$FIRST_SERVER:/home/site-name2/public/images/ovinterface/
scp -P (port number) -r /Users/Aston/Sites/site-name3/Christmas\ graphics/normal-graphics/interface/* root@$FIRST_SERVER:/home/site-name3/public/images/interface/
...
}
I’m sure I could improve a lot of it (eg: just use numbers instead of words for servers) but it’s not a huge priority for me right now…
I’m also surprised at the size of your file, mine’s about 145 lines and includes some functions for:
I thought it was overgrowing tbh. I guess not?
$ wc -l .config/zsh/.zshrc
99 .config/zsh/.zshrc
I’m surprised it’s this big. Though indeed, I can explain about any of those lines and why it is there.
But can’t copy the full file, as I’m on mobile.
Also that’s just one computer, the other is currently offline.
Hi @AstonJ , I can suggest trying out .ssh/config https://man.freebsd.org/cgi/man.cgi?query=ssh_config&sektion=5&apropos=0&manpath=FreeBSD+14.3-RELEASE+and+Ports
With combination with rsync https://man.freebsd.org/cgi/man.cgi?query=rsync&apropos=0&sektion=0&manpath=FreeBSD+14.3-RELEASE+and+Ports&arch=default&format=html
I do also administer few server on daily basis, and with .ssh/config and rsync I’ve minimized a lot of typing and erros.
Just an idea as I was in similar situation.
Thanks Dimitrije ![]()
How are you using .ssh/config? (How do you think it could help me?)
I’ve used rsync in the past (eg for Jekyll sites) but ended up preferring scp (I can’t remember exactly why now tho
)
Aston, you didn’t ask about fish, and its configuration is fairly different than bash/zsh, but here you go…
wc -l .config/fish/config.fish .config/fish/functions/*
102 total
Almost none of those lines were added to those files by me (maybe ~10 lines I actually wrote), most of it came from me using fish functions from the command line and it writing to those files.
Assuming you have environment variables you are exporting from your rc file, fish has a dedicated file for those, and most of mine are for configuring fish itself. And again, I didn’t write any of those lines, most came from running fish_config, the rest from setting variables from the command line:
wc -l .config/fish/fish_variables
68
cat .config/fish/fish_variables | grep -v fish | wc -l
16
Sorry Jacob - every shell user is welcome to join in
(I’ve edited the title and tags)
1992 lines…
You could simplify, or even get rid of your upload file thing, just by leveraging ssh configuration in the first place.
How do you mean Norbert? (Can you give me some examples?)
Am curious what’s in yours now Andy..
By configuring each hosts port and user. You could just use scp server:index.html index.html or scp index.html server:index.html. so either direction would be the same use, just with swapped arguments.
You even can use aliases.
Sadly I am on my phone and copying is annoying, so I can only give you the simpler parts of an example. And I do not have to worry about ports in my scenario. All the servers use the default.
Host *.internal.nobbz.dev
User nmelzer
IdentityFile ~/.ssh/id_rsa
Host *.nobbz.dev
User root
IdentityFile ~/.ssh/nobbz_dev
Host aarch64-build-box.nix-community.org
User nobbz
IdentityFile /home/nmelzer/.ssh/nix-community
Host build-box.nix-community.org
User nobbz
IdentityFile /home/nmelzer/.ssh/nix-community
I’ve got it broken out into a dozen or so files: functions, aliases, completions, encryption stuff, some written by me, some by 3rd parties (eg fzf).
function sourcefile() {
[ -f $1 ] && source $1
}
sourcefile ~/.rails_env
sourcefile ~/.bash_aliases
sourcefile ~/.bash_functions
sourcefile ~/.bash_marks
sourcefile ~/.mix_completions.bash
...
I guesstimate probably there is more than 15K lines of config in total. Performance is very good! (Xubuntu 24.04).
Nice! This has shortened some of my functions and made them more maintainable (by not needing to be updated every time I commission a new server):
upload_file() {
# Usage: upload_file <local_file> <remote_path> <server>
# Servers: first, second, third (or s1, s2, s3) etc
# $server variable is set to 'first' if <server> argument is not passed
server=${3:-first}
scp $1 $server:$2
}
Thank you (and @dimitrije!)
Mine is just 30-ish lines but it includes 25+ separate files.
tokei reports 348 zsh lines in total. I am configuring loads of aliases and programming-language-specific configurations.
Anecdotal - I switched from using scp to rsync and found rsync is much faster. Recommend
server=${3:-first}
rsync -qavzrP $1 server:$2
I can’t remember why I stopped using it (though see I do still use it for Jekyll site uploads) but IIRC there were some downsides as to why I opted for plain old SCP. I quickly asked Google about its downsides and it said this.