alexanderepstein / Bash-Snippets

A collection of small bash scripts for heavy terminal users
MIT License
9.64k stars 842 forks source link

Duplicate functions #158

Closed Hickory420 closed 6 years ago

Hickory420 commented 6 years ago

Issue Label:

Description:

Is there any particular reason why you have the following functions in every script?

getConfiguredClient()
httpGet()
checkInternet()

etc...

Is there any reason why (within each script) you don't do something like source ../common_functions.sh, where ../common_functions.sh would be the above functions in the root directory?

This would save on a lot of code duplication.

That being said, I don't know if source exists on Mac, but I would be surprised if it didn't.

I am happy to contribute towards this, if you like?

Cheers, Hickory

alexanderepstein commented 6 years ago

This is not a bad idea, I did realize that I was doing this and I was left with the choice of doing what you stated above but went with the idea that each script is self contained. Which means that someone doesn't even have to go through my installer to use the script. I was also worried this might cause naming conflicts on somebodies system. I would be open to hearing what others have to say about this and if it is understood that I made the incorrect decision we can definitely look into implementing this.

navanchauhan commented 6 years ago

I think standalone scripts are better, it's easier to develop and also the size is not a factor. Also @Hickory420 source indeed exists on mac

Hickory420 commented 6 years ago

It is true that the duplicate code allows for portability of each script. Simply copy the contents of the script into a file and off they go. There is value in that.

On the other side of the coin, what happens when you need to update the skeleton script? Do you leave all the other scripts as they are, or manually (or via automated means) go through each script and update the 'skeletal' parts?

Coincidentally, I have been doing something similar to this project before I came across this (https://github.com/Hickory420/where). The difference is I use a single script with a bucket ton of functions. So, in translation, all of your scripts would be functions called from a main script with switches. For example alex.sh --scriptname and it would run that function. I guess the downside to that is you will end up with a rather lengthy script that is very much integrated with itself, but the upside is one script and you get everything. getopts would solve issuing arguments to functions (even though I don't use getopts in my script... yet) :P

Anyway, Just some food for thought.

Cheers.

alexanderepstein commented 6 years ago

To update the skeleton script and all the other files that include the similar code I use a tool called rpl it lets you specify a folder to recursively search for a given piece of text and replace it with another piece of text. (This is also how I update the version of bash-snippets because each file has their own version variable). I threw a little function in my .bashrc to facilitate doing this to specifically all the bash-snippets so it isnt to bad from a development standpoint. I will keep this issue open for a bit as I will think about implementing this and will close the issue either when I decide not to go this route or actually implement it.

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 6 years ago

This issue has been automatically closed because it has been inactive for 30 days.