Skip to content

Instantly share code, notes, and snippets.

@prenaux
prenaux / pathenv_in_ham.sh
Created July 31, 2022 15:07
Add/remove path from the PATH environment variable
pathenv_add() {
if [ ! -d "$1" ]; then
return 0
fi
DIR=$(unxpath "$1")
if [ -z "$PATH" ]; then
PATH=$DIR
elif [ -d "$DIR" ] && [[ ":$PATH:" != *":$DIR:"* ]] ; then
if [ "$2" = "after" ] ; then
export PATH=$PATH:$DIR
@prenaux
prenaux / _build.ham
Created October 25, 2022 11:46
ham rules to generate Protoc C++
# ProtocToCpp TARGET : input.proto ;
rule ProtocToCpp {
local genDir = _pb ;
local input = [ FGristFiles $(2) ] ;
local cpp = [ FGristFiles [ FDirName $(input:D) $(genDir) $(input:B).pb.cc ] ] ;
local h = [ FGristFiles [ FDirName $(input:D) $(genDir) $(input:B).pb.h ] ] ;
local outDir = [ FGetAbsolutePath [ FDirName $(input:D) $(genDir) ] ] ;
ProtocRun_ $(cpp) $(h) : $(input) : $(genDir) : $(outDir) ;
DEPENDS protoc-to-cpp : $(cpp) $(h) ;