recentpopularlog in

kme : scripting   180

« earlier  
How to Copy Command Line Output to the Windows Clipboard | https://www.labnol.org/
So there's a 'clip' utility on Windows that works like 'pbcopy' or 'xclip' on other OSes, but *only* for input.
windows  textprocessing  clipboard  commandline  scripting  sortof  solution  cli 
february 2019 by kme
image manipulation - Create drop shadow effects in Imagemagick - Stack Overflow
<code class="language-bash">convert input.jpeg -bordercolor white -border 13 \( +clone -background black -shadow 80x3+2+2 \) +swap -background white -layers merge +repage output.jpg
</code>

As a gist: https://gist.github.com/ernstki/742a2140047e74804572d7e3e95a80d4
imagemagick  dropshadow  imageprocessing  solution  commandline  scripting  fuckina 
july 2018 by kme
Add Shadow and Border to Images with ImageMagick | bemoko's blog on mobile
<code class="language-bash">image-shadow () {
out=${1%.*}-shadow.${1#*.}
in=$1
echo "Converted file : $out"
if [ ! -z $2 ] ; then
convert $in -frame $2 $out
in=$out
fi
convert $in \( +clone -background black -shadow 60x5+10+10 \) \
+swap -background white -layers merge +repage $out
}</code>
magemagick  imageprocessing  dropshadow  imagemanipulation  scripting  solution  fuckina 
july 2018 by kme
Random Renegade Bits > Solved: GIMP Script-Fu Console Image ID | http://rrbits.com/
<code class="language-scheme">(script-fu-round-corners 1 (car (gimp-image-get-active-drawable 1)) 30 1 6 6 20 1 0)</code>
script-fu  gimp  scripting  imageprocessing  howto  solution 
may 2018 by kme
GNU Parallel and Block Size(s) | Jeremy Zawodny's blog | https://blog.zawodny.com/
And, finally, I put the pieces together when I came across the notion of “blocks” and then saw this in the section about piping:

Spread input to jobs on stdin (standard input). Read a block of data from stdin (standard input) and give one block of data as input to one job. The block size is determined by –block.

The default block size is 1MB. How big was my input file? Event though it contained hundreds of thousands of primary keys, it was about 2.5MB in size.
gnuparallel  tipsandtricks  parallelism  commandline  scripting 
january 2018 by kme
PEP 397 -- Python launcher for Windows | Python.org
See also: https://docs.python.org/3/using/windows.html#launcher

Basically: put the Python interpreter version in the shebang to specify which version your scripts need, and you can run 'py -2' to get the Python 2.x version if you have both installed.
python  windows  fileassociations  shebang  scripting 
december 2017 by kme
Get the name of current script with Python - Stack Overflow | https://stackoverflow.com/
<code class="language-python">
os.path.basename(__file__)
# or
sys.argv[0]
</code>
python  scripting  dammitbrain  solution 
december 2017 by kme
python - Read password from stdin - Stack Overflow | https://stackoverflow.com/
<code class="language-python">
>>> import getpass
>>> pw = getpass.getpass()
</code>
python  security  password  prompt  scripting  tui  batteriesincluded  solution 
december 2017 by kme
GitHub - AutoKey, a desktop automation utility for Linux and X11
Looks like you need to install either or both of libdbus-1-dev and libdbus-glib-1-dev.

On later Ubuntus (18.x-ish) and elementaryOS Juno (5.0) you randomly needed to install gir1.2-gtksource-3.0, otherwise you get an error about namespaces not being available.
automation  hotkey  scripting  python  python3  needshelp  alternativeto  texter  textexpander  phraseexpress 
november 2017 by kme
Where Tcl and Tk Went Wrong (2010) | Hacker News | https://news.ycombinator.com/
I've read that he'd wanted to just use Scheme, but that they needed the language to have "Java" in the name, as well as curly braces. So, we got Javascript.

Also, given that DSSSL was an early contender against CSS (and a great deal more powerful), we could have basically had Scheme there too. https://blog.cloudflare.com/the-languages-which-almost-becam...

Lastly, because S-expressions can represent everything that is representable in SGML/XML/(X)HTML, but more succinctly, we could have basically had Scheme instead of HTML.

Imagine if, instead of JS/HTML/CSS, we had... Scheme. I'm pretty sure that the alter universes where this happened also all have peace, warp drives, and working cold fusion.


From Eich:
Study history or you, too, may be doomed to repeat it:

https://devchat.tv/js-jabber/124-jsj-the-origin-of-javascrip... (transcript at bottom)

https://brendaneich.com/2012/04/the-infernal-semicolon/#comm...

Netscape management gave "make it look like Java" orders. There was no time, on top of this. Last (more below in another reply) no extant command line interpreter was ready to be put in a browser. Way too many non-portable OS dependencies, unsafe FFI, etc. It was JS or bust (aka VBScript).

Thats actually not totally true. Internally, Tcl has two value types, string representation and actual value representation. Everything DOES have a string-representation though- some are made up (like file handles, fileX) and some are just ASCII forms of the values underneath (like integers).

Tcl is cool because you can manipulate the string form of values incredibly easily, but people confused this with "Everything is a string". It should be "Everything can be manipulated like a string".
tcl  programming  scripting  language  thestoryof  alsoran  vs  javascript  theweb 
november 2017 by kme
How to Extract ZIP Files Using PowerShell [https://www.howtogeek.com/]
function Expand-ZIPFile($file, $destination)
{
$shell = new-object -com shell.application
$zip = $shell.NameSpace($file)
foreach($item in $zip.items())
{
$shell.Namespace($destination).copyhere($item)
}
}
windows  sysadmin  powershell  scripting  compression  archive  maybesolution 
august 2017 by kme
Script Download files from websites programatically via powershell [https://gallery.technet.microsoft.com/]
$url = "http://website.com/downloads/Iwantthisfile.txt"
$path = "C:\temp\thisisthefile.txt"
# param([string]$url, [string]$path)

if(!(Split-Path -parent $path) -or !(Test-Path -pathType Container (Split-Path -parent $path))) {
$path = Join-Path $pwd (Split-Path -leaf $path)
}

"Downloading [$url]`nSaving at [$path]"
$client = new-object System.Net.WebClient
$client.DownloadFile($url, $path)
#$client.DownloadData($url, $path)

$path
powershell  scripting  webdevel  maybesolution 
august 2017 by kme
Functions - Global variables
Solution: inside a function, just use the 'global' keyword to pull in all variables from the global scope.
ahk  autohotkey  scripting  syntax  solution 
may 2017 by kme
Batch files - Errorlevels
In Windows NT 4/2000/XP this may sometimes fail, since some executables return negative numbers for errorlevels!
However, this can be fixed by using the following code to check for non-zero return codes:
IF %ERRORLEVEL% NEQ 0 ...
Use the code above wherever you would have used IF ERRORLEVEL 1 ... in the "past".
dos  batchscripting  scripting  annoyance  windows  sysadmin  errorhandling  solution 
may 2016 by kme
How can I exit a batch file from within a function? - Stack Overflow
The 'exit /b' doesn't seem to be required, but this does work.

:halt
call :haltHelper 2> nul

:haltHelper
()
exit /b
dos  scripting  batchscripting  wtf  windows  solution 
may 2016 by kme
command line - Download a file via HTTP from a script in Windows - Super User

If you have PowerShell >= 3.0, you can use Invoke-WebRequest:

Invoke-WebRequest -OutFile su.htm -Uri superuser.com

Or golfed:

curl -outf su.htm superuser.com
networking  bits  windows  commandline  scripting  maybesolution  alternativeto  curl  wget 
april 2016 by kme
Shell Scripts vs Ansible: Fight!
After writing my book on configuration management (CM) tools, I sent out review copies to about 20 people, including some very well-known developers. What really surprised me was the response from some of these more famous devs. They basically said, "This is really cool, but I probably won't read it since my manual-install/shell-script workflow is fine for now."



Michael Booth captures the sentiment well in his Hacker News comment:

As a veteran user of Puppet I'm a firm believer in using a tool like Puppet, but Puppet-and-Chef are overdesigned for small jobs (and, arguably, for most other jobs as well) so actually recommending them to a beginner has always felt like this:

A: "I just set up a cloud instance by running some shell commands by hand."

B: "You shouldn't do that, because of X and Y and Z. You should learn Puppet or Chef."

A: "Wait... did you just tell me to go spend thirty hours banging my head against solid objects, in exchange for nebulous benefits that I can't even perceive yet?"

B: "Why, yes, I believe I did!"
passenger  ansible  devops  automation  scripting  puppet  chef  cm  advice 
april 2016 by kme
bash - How to detect if my shell script is running through a pipe? - Stack Overflow
Pure POSIX shell:

if [ -t 1 ] ; then echo terminal; fi

returns "terminal", because the output is going straight to you, while

(if [ -t 1 ] ; then echo terminal; fi) | cat

returns nothing, because the output is going to cat.
bash  shellscripting  terminal  scripting  reference  solution 
march 2016 by kme
moreutils
On SuSE Linux, you'll have to modify the Makefile to use /usr/share/xml/docbook/stylesheet/nwalsh/current/manpages/docbook.xsl instead of whatever's in there by default (probably Debian's default location).
bash  sysadmin  cli  commandline  filemanagement  scripting  utility  software 
march 2016 by kme
Bash Shell Scripting Disable Control-C [ CTRL+C ] Keys - http://www.cyberciti.biz/
Moral of the story is: don't trap signal 2 if you don't plan to do something with it. I couldn't for the life of me figure out why I couldn't break out of 'read' prompts in a script, and this was why.
bash  signals  scripting  errorhandling  tipsandtricks  shellscripting  solution 
march 2016 by kme
stdin/stdout pipe in node.js · GitHub
process.stdin.resume()
process.stdin.on('data', function(data) { process.stdout.write(data) })
process.stdout.on('error', function(err) {
if (err.code === 'EPIPE') return process.exit()
process.emit('error', err)
})
nodejs  javascript  scripting  stdin  stdout  solution 
february 2016 by kme
shell - Generating permutations using bash - Stack Overflow - http://stackoverflow.com/
perm() {
local items="$1"
local out="$2"
local i
[[ "$items" == "" ]] && echo "$out" && return
for (( i=0; i<${#items}; i++ )) ; do
perm "${items:0:i}${items:i+1}" "$out${items:i:1}"
done
}
while read line ; do perm $line ; done < File
bash  braceexpansion  permutations  solution  scripting 
november 2015 by kme
shell - Check if a program exists from a Bash script - Stack Overflow - http://stackoverflow.com/
Ran into a weird problem on 2015-11-11 where 'which' wasn't finding something that was *definitely* in the PATH that it (!) reported.
which  bash  scripting  gotchas  bestpractices  solution 
november 2015 by kme
Print the perl script's path without resolving symlink - Stack Overflow

#!/usr/bin/perl

use strict;
use warnings;

use Path::Tiny;


my $path = path(__FILE__);

print $path->absolute->parent, "\n";
perl  scripting  solution 
november 2015 by kme
erichs/composure · GitHub
Ach so! 'typeset' is just an alias for 'declare'.
Retrieve your metadata later by calling 'metafor ()':

typeset -f foo | metafor about # displays:
perform mad script-foo
unix  shellscripting  repl  scripting  cli  bash  utility  software 
september 2015 by kme
Quotes - Greg's Wiki
When Should You Quote?

The basic rule of thumb is that you should double-quote every expansion. This prevents unwanted word splitting and globbing. When in doubt, quote it.

There are a few cases where double quotes may be safely omitted:

On the right hand side of a simple assignment. You may write foo=$bar without quotes. This is POSIX compliant.

The word following a case keyword. You may write case $foo in ... safely. This is POSIX compliant.

Inside a [[ command, except on the right hand side of an = or == operator. [[ already suppresses word splitting and globbing, so you can write things like [[ -z $string ]] safely if you wish. However, be warned that [[ foo = $bar ]] and [[ foo = "$bar" ]] act differently (see patterns below). The [[ keyword is a Bash extension.

Use single quotes when protecting complex strings, especially ones that contain shell syntax which you don't want evaluated.
quoting  sysadmin  linux  devel  shellscripting  scripting  bash  bestpractices  reference  arrays  essential 
july 2015 by kme
removing a space from a string by awk - Stack Overflow
gsub is your friend. The following command basically does a global substitution of a regular expression (a single space in this case), replacing it with an empty string, on the target $0 (the whole line).

pax> echo "steve john" | awk '{ gsub (" ", "", $0); print}'
stevejohn
awk  shellscripting  scripting  textprocessing  solution 
july 2015 by kme
string - Extract filename and extension in Bash - Stack Overflow
First, get file without path:

filename=$(basename "$fullfile")
extension="${filename##*.}"
filename="${filename%.*}"

Alternatively, you can focus on the last '/' of the path instead of the '.' which should work even if you have unpredictable file extensions:

filename="${fullfile##*/}"
bash  essential  shellscripting  scripting  sysadmin  solution  dammitbrain 
july 2015 by kme
Use the Unofficial Bash Strict Mode (Unless You Looove Debugging)
I take your point, sir,
By default, bash does not do this. This default behavior is exactly what you want if you are using bash on the command line - you don't want a typo to log you out! But in a script, you really want the opposite. If one line in a script fails, but the last line succeeds, the whole script has a successful exit code. That makes it very easy to miss the error.


but apart from 'set -u', I really got tired of 'set -e' trickfucking me, whenever I wrote a function that returned non-zero on purpose, then had other functions calling it. This actually logs you out, or closes your tmux/Screen split. Super-annoying.
Let's start with the punchline. Your bash scripts will be more robust, reliable and maintainable if you start them like this:

#!/bin/bash
set -euo pipefail
IFS=$'\n\t'


See also: https://news.ycombinator.com/item?id=8054440

Relevant quotes:

quotemstr 353 days ago
I don't think that setting IFS this way is a good idea. Of your variables do happen to contain tabs and newlines, you still get unwanted word expansion. Much better is to just use double quoted expansion primitives that always expand one element to each word: "${foo[@]}"


staticshock 353 days ago
Agreed. The IFS trick is shortly followed by an explanation, which includes a bunch of anti-patterns, such as bare ${foo[@]} and $@ usage.

Rule of thumb: quote all your variables.

http://mywiki.wooledge.org/Quotes
bash  shellscripting  scripting  strictmode  bestpractices 
july 2015 by kme
Color Output on Bash Scripts | Linuxtidbits
<code class="language-bash">#!/bin/bash
# scriptname - description of script

# Text color variables
txtund=$(tput sgr 0 1) # Underline
txtbld=$(tput bold) # Bold
bldred=${txtbld}$(tput setaf 1) # red
bldblu=${txtbld}$(tput setaf 4) # blue
bldwht=${txtbld}$(tput setaf 7) # white
txtrst=$(tput sgr0) # Reset
info=${bldwht}*${txtrst} # Feedback
pass=${bldblu}*${txtrst}
warn=${bldred}*${txtrst}
ques=${bldblu}?${txtrst}</code>

Also, a helpful demo script:

<code class="language-bash">#!/bin/bash
# tputcolors

echo
echo -e "$(tput bold) reg bld und tput-command-colors$(tput sgr0)"

for i in $(seq 1 7); do
echo " $(tput setaf $i)Text$(tput sgr0) $(tput bold)$(tput setaf $i)Text$(tput sgr0) $(tput sgr 0 1)$(tput setaf $i)Text$(tput sgr0) \$(tput setaf $i)"
done

echo ' Bold $(tput bold)'
echo ' Underline $(tput sgr 0 1)'
echo ' Reset $(tput sgr0)'
echo</code>
tput  terminal  colors  ansi  shellscripting  scripting  bash  reference  solution 
june 2015 by kme
« earlier      
per page:    204080120160

Copy this bookmark:





to read