3 ms·
You can do feature creep for a long time. If you just want a basic working version (that will probably drain your battery), that can be done really quickly. Th
by chmod775 5y ago
You can do feature creep for a long time. If you just want a basic working version (that will probably drain your battery), that can be done really quickly.
This took me ~10 minutes:
#!/bin/sh
set -e
while true; do
URLS="$(xsel | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*")" &&
if [[ ! "${URLS}" = "${OLD_URLS}" ]]; then
echo "${URLS}" >> urls.txt
OLD_URLS="${URLS}"
fi
sleep 1
done;
- thewakalix 5y agoUsing clipnotify[0], one could fix the busy-wait issue pretty easily. [0] https://github.com/cdown/clipnotify https://github.com/cdown/clipnotify
- dugmartin 5y agoIsn't the >> going to cause urls.txt to grow geometrically? eg, copying http://example.com/foo http://example.com/foo and then http://example.com/bar http://example.com/bar and then http://example.com/baz http://example.com/baz I think urls.txt would look like: http://example.com/foo http://example.com/foo http://example.com/bar http://example.com/foo http://example.com/bar http://example.com/baz EDIT: I stand corrected. I should have run the code instead of mentally executing it. One issue I did find when I ran it. The shebang should be: #!/bin/bash as [[ is a bash built-in. I'm on Ubuntu - maybe this works on Mac as /bin/sh is an alias to /bin/bash?
- BenjiWiebe 5y agoDoesn't look like it. The URLS variable could more appropriately be named CURRENT_URL. Singular, not plural.
- stevelosh 5y agoThe user might copy a block of text with multiple URLs, all of which get pulled out by the grep.
- deleted 5y ago[deleted]
- ktpsns 5y agoNo, >> is just doing appending, cf. https://wiki.bash-hackers.org/syntax/redirection#appending_redirected_output https://wiki.bash-hackers.org/syntax/redirection#appending_r...
- sporedro 5y agoNice example, the problem with the article is the client(teacher) doesn’t know what they want in this case. It’s a good example of how feature creep and project scoping is important but if all you really want is a script to log urls that’s simple. Building a url logger with top notch security practices, cross platform, simple enough for my mom to use would be entirely different.
- barnabee 5y agoAgree! Furthermore the reason we have such bloated and garbage software is a combination of this kind of feature creep and a complete lack of modularity. Want pause functionality: write a small utility to provide an easy way to start and kill any program. Want notifications: write a program to monitor any file and provide notifications when something it added to it. Searching: grep or a GUI equivalent Syncing: rsync/syncthing/Dropbox… Someone will complain most people can’t use these tools. Firstly that wasn’t the initial question, and secondly that’s something I’d love to see tackled in a GUI tool. I don’t think it’s impossible, just misaligned with the incentives of people who make and overcharge for proprietary software.