How to load zsh/mapfile in ZSH - macos

I have installed zsh version 5.6.2 via brew. I am having trouble loading mapfile module.
adding zmodload zsh/mapfile mapfile gives error ~/.zshrc:15: failed to load module 'mapfile': dlopen(/usr/local/Cellar/zsh/5.6.2_1/lib/mapfile.bundle, 9): image not found
Anyone know how to debug this or a fix ?

To load the zsh/mapfile module, just run
zmodload zsh/mapfile
You can check that it's correctly loaded with:
zmodload
You should then see the following list of loaded modules:
zsh/complete
zsh/main
zsh/mapfile
zsh/parameter
zsh/zle
zsh/zutil
You can then use it, for example, such as:
# Define a file named pp with three lines
echo yay1 >> pp
echo yay2 >> pp
echo yay3 >> pp
# Build the associative array
arr=("${(f#)mapfile[pp]}")
# Show the content
echo $arr[1]
echo $arr[2]
echo $arr[3]
For explanation about the mapfile module see ZSH Gem #22: Accessing and editing files with mapfile.
For details about the Parameter Expansion Flags see the corresponding section in the Zsh documentation.

Related

Modules not loaded into environment [duplicate]

This question already has answers here:
How to pipe input to a Bash while loop and preserve variables after loop ends
(3 answers)
Closed 9 months ago.
I have the following line in my .bashrc file:
cat "$HOME/.module_list" | while read m; do echo "Loading module $m..."; module load "$m"; done
where $HOME/.module_list is a file that contains the name of a module to load on each row. When .bashrc is sourced, the line goes through each module in the list one by one and seemingly loads them, but afterwards, when I do module list, none of the modules are loaded.
Does this line create a new scope into which the modules are loaded, which is then terminated as soon as the line finishes, or why aren't the modules still loaded afterwards? How can I successfully load all modules from the list and still have them be loaded afterwards?
A simple solution is to load your modules names into an array:
#!/bin/bash
readarray -t modules < ~/.module_list
module load "${modules[#]}"
An other solution is to use a while read loop, making sure to avoid the |:
#!/bin/bash
while IFS='' read -r m
do
module load "$m"
done < ~/.module_list

Setting Puppet variables with a BASH command

I've been trying to set a variable in a Puppet manifest that can be used across the puppet run. I have the following variables:
$package = 'hello'
$package_ensure = 'present'
$package_version = '4.4.1'
$package_maj_version = '4'
I'm trying to add another variable:
$ensure
using a BASH If statement using the above variables (since this is a source install I can't use an rpm command to see if the hello program is installed):
if [ -d "/opt/${package}${package_maj_version}" ]; then echo present; else echo absent; fi
but, I haven't been able to find a way to do so. I keep getting errors such as:
Error: Could not parse for environment production: Could not match ${package}${package_maj_version}"
Any help on this would be greatly appreciated.

Execute mustache (as ruby script) in cmake execute_process

I would like to use mustache as a simple templating engine in cmake for code generation.
I tried to execute it with execute_process as follow:
execute_process( COMMAND "/path/to/mustache" "<data> <template>" )
But it said its not a valid WIN32 application. And indeed, mustache is a ruby script:
#!D:/programs/Ruby23/bin/ruby.exe
#
# This file was generated by RubyGems.
#
# The application 'mustache' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = ">= 0.a"
if ARGV.first
...
So I tried:
execute_process( COMMAMD "/path/to/ruby" "/path/to/mustache --help" )
But it don't work either... No such file or directory -- D:/programs/Ruby23/bin/mustache --help (LoadError)
How to execute a ruby script in cmake execute_process?
execute_process(COMMAND < cmd1 > [args1...]] ...)
Arguments must be passed as list, not as string.
# path to executables
set(RUBY_EXECUTABLE D:/programs/Ruby23/bin/ruby.exe CACHE STRING "ruby executable")
set(MUSTACHE_SCRIPT D:/programs/Ruby23/bin/mustache CACHE STRING "mustache ruby script")
# function that call mustache
function(apply_mustache data template result)
execute_process(
COMMAND ${RUBY_EXECUTABLE} -E UTF-8 ${MUSTACHE_SCRIPT} ${data} ${template}
OUTPUT_VARIABLE result_t
)
set(${result} ${result_t} PARENT_SCOPE)
endfunction()
bonus: -E UTF-8 prevent ruby to mess with utf-8 characters...

What does it mean $: in Ruby

I was reading the following tutorial.
It talked about including files in a Ruby file like require :
require(string) => true or false
Ruby tries to load the library named string, returning true if
successful. If the filename does not resolve to an absolute path, it
will be searched for in the directories listed in $:. If the file has
the extension ".rb", it is loaded as a source file; if the extension
is ".so", ".o", or ".dll", or whatever the default shared library
extension is on the current platform, Ruby loads the shared library as
a Ruby extension. Otherwise, Ruby tries adding ".rb", ".so", and so on
to the name. The name of the loaded feature is added to the array in
$:.
I just want to know what is $: in Ruby and what does $: means.
The variable $: is one of the execution environment variables, which is an array of places to search for loaded files.
The initial value is the value of the arguments passed via the -I command-line option, followed by an installation-defined standard library location.
See Pre-defined variables, $LOAD_PATH is its alias.
Its the load path
Just open in irb terminal and type this $:
This is what you would get. Ofcourse that depends on the ruby ur using.
2.1.1 :009 > $:
=> ["/Users/mac/.rvm/rubies/ruby-2.1.1/lib/ruby/site_ruby/2.1.0", "/Users/mac/.rvm/rubies/ruby-2.1.1/lib/ruby/site_ruby/2.1.0/x86_64-darwin12.0", "/Users/mac/.rvm/rubies/ruby-2.1.1/lib/ruby/site_ruby", "/Users/mac/.rvm/rubies/ruby-2.1.1/lib/ruby/vendor_ruby/2.1.0", "/Users/mac/.rvm/rubies/ruby-2.1.1/lib/ruby/vendor_ruby/2.1.0/x86_64-darwin12.0", "/Users/mac/.rvm/rubies/ruby-2.1.1/lib/ruby/vendor_ruby", "/Users/mac/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0", "/Users/mac/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/x86_64-darwin12.0"]
2.1.1 :010 >
In ruby $ refers to a predefined variable.
In this case, $: is short-hand for $LOAD_PATH. This is the list of directories you can require files from while giving a relative path. In other words, Ruby searches the directories listed in $:
Hope this helps.

Scripting Xcode documentation with DOxygen problems

I am trying to use the following script by duckrowing (http://www.duckrowing.com/2010/03/18/documenting-objective-c-with-doxygen-part-ii/), to document an existing xcode project.
#
# Build the doxygen documentation for the project and load the docset into Xcode
#
# Created by Fred McCann on 03/16/2010.
# http://www.duckrowing.com
#
# Based on the build script provided by Apple:
# http://developer.apple.com/tools/creatingdocsetswithdoxygen.html
#
# Set the variable $COMPANY_RDOMAIN_PREFIX equal to the reverse domain name of your comany
# Example: com.duckrowing
#
DOXYGEN_PATH=/Applications/Doxygen.app/Contents/Resources/doxygen
DOCSET_PATH=$SOURCE_ROOT/build/$PRODUCT_NAME.docset
if ! [ -f $SOURCE_ROOT/Doxyfile]
then
echo doxygen config file does not exist
$DOXYGEN_PATH -g $SOURCE_ROOT/Doxyfile
fi
# Append the proper input/output directories and docset info to the config file.
# This works even though values are assigned higher up in the file. Easier than sed.
cp $SOURCE_ROOT/Doxyfile $TEMP_DIR/Doxyfile
echo "INPUT = $SOURCE_ROOT" >> $TEMP_DIR/Doxyfile
echo "OUTPUT_DIRECTORY = $DOCSET_PATH" >> $TEMP_DIR/Doxyfile
echo "RECURSIVE = YES" >> $TEMP_DIR/Doxyfile
echo "EXTRACT_ALL = YES" >> $TEMP_DIR/Doxyfile
echo "JAVADOC_AUTOBRIEF = YES" >> $TEMP_DIR/Doxyfile
echo "GENERATE_LATEX = NO" >> $TEMP_DIR/Doxyfile
echo "GENERATE_DOCSET = YES" >> $TEMP_DIR/Doxyfile
echo "DOCSET_FEEDNAME = $PRODUCT_NAME Documentation" >> $TEMP_DIR/Doxyfile
echo "DOCSET_BUNDLE_ID = $COMPANY_RDOMAIN_PREFIX.$PRODUCT_NAME" >> $TEMP_DIR/Doxyfile
# Run doxygen on the updated config file.
# Note: doxygen creates a Makefile that does most of the heavy lifting.
$DOXYGEN_PATH $TEMP_DIR/Doxyfile
# make will invoke docsetutil. Take a look at the Makefile to see how this is done.
make -C $DOCSET_PATH/html install
# Construct a temporary applescript file to tell Xcode to load a docset.
rm -f $TEMP_DIR/loadDocSet.scpt
echo "tell application \"Xcode\"" >> $TEMP_DIR/loadDocSet.scpt
echo "load documentation set with path \"/Users/$USER/Library/Developer/Shared/Documentation/DocSets/$COMPANY_RDOMAIN_PREFIX.$PRODUCT_NAME.docset\"" >> $TEMP_DIR/loadDocSet.scpt
echo "end tell" >> $TEMP_DIR/loadDocSet.scpt
# Run the load-docset applescript command.
osascript $TEMP_DIR/loadDocSet.scpt
exit 0
However, I am getting these errors
Osascript:/Users/[username]/SVN/trunk/Examples: No such file or directory
Earlier in the script output (in xcode window after building) I see these msgs:
Configuration file '/Users/[username]/SVN/trunk/Examples' created
the problem I think is that the full path is actually
'/Users/[username]/SVN/trunk/Examples using SDK'
I was working on the assumption that the whitespaces were the culprit. So I tried two approaches:
$SOURCE_ROOT = "/Users/[username]/SVN/trunk/Examples using SDK"
$SOURCE_ROOT = /Users/[username]/SVN/trunk/Examples\ using\ SDK
set $SOURCE_ROOT to quoted form of POSIX path of /Users/$USER/SVN/trunk/Examples\ using\ SDK/
but all give the same Osascript error as above. Also, the docset is not build into the requested directory
/Users/$USER/Library/Developer/Shared/Documentation/DocSets/$COMPANY_RDOMAIN_PREFIX.$PRODUCT_NAME.docset\
I've scratched my head over this for a while but can't figure out what is the problem. One hypothesis is that I am running Doxygen on a project that is not a new project. To handle this EXTRACT_ALL is set to YES (which should remove all warning messages, but I get 19 warnings too).
Any help would be much appreciated
thank you
Peyman
I suggest that you double quote "$SOURCE_ROOT" wherever you use it in your shell script.
Mouviciel....i figured it out....needed to put the whole variable in parenthesis i.e. $(SOURCE_ROOT).
thank you for your help

Resources