Turborepo/pnpm workspaces: build my package and every package I depend on - pnpm

I have three packages in my turborepo monorepo, top, middle, and bottom. top depends on middle and middle depends on bottom.
If I do this:
cd bottom
make some edits
cd ../middle
make some edits
I want to type something in that directory (middle) that will build everything that middle depends on (i.e. bottom) and middle itself.
I know I can cd to the root of the project and do this:
turbo run build --filter=middle...
but I want a command (or a script) that knows what directory I am in and basically says "build everything up to and including here"

In case it's of use to any one, I added this to by .zshrc:
find-up () {
path=$(pwd)
while [[ "$path" != "" && ! -e "$path/$1" ]]; do
path=${path%/*}
done
echo "$path"
}
bt () {
ROOT_DIR=$(find-up "pnpm-workspace.yaml")
PKG_NAME=$(npm pkg get name | sed -e s#\"##g)
(cd $ROOT_DIR && pnpm run build --filter=$PKG_NAME...)
}
Now I can cd into middle and type bt (standing for build to) and it will build everything up to and including the current package. Would love to know a better way!

Related

Variable for a right-clicked item (say, a jpg) in a bash script?

I have a very simple bash script that I run often from the cli, but I've found it's frustrating to have to open a terminal, identify the right file, and run it and think the easiest way would be to run it as an option from a right-click. I am running Ubuntu 18.04 LTS.
The script is just erasing exif data, leaving the orientation tags, essentially this:
exiftool -all= -tagsfromfile # -Orientation file-*.jpg
Is there a way to have the script identify which image I'm right clicking on? I'm at a loss what to put in the file-*.jpg part which will be a variable for "whatever image I'm right-clicking on right now."
Tried searching for a good while on how to do this but am clearly either not using the right search terms or else this isn't done very often. Thank you in advance for any help!
if you want your script to run in file manager right-click menu you have to change your script and define file(s) as arguments. this happens simply by changing your file section with $1 to $n as the parameter(s).
as far as I know ubuntu uses nautilus as an file manager.
you can run nautilus-actions-config-tool either from your terminal or from dash and define your script a name and a command to run. you can follow this link for illustration learning :
ubuntu nautilus defile script in menu
for example :
#!/bin/bash
if [ "$1" != "" ]; then
echo "Positional parameter 1 contains value $1"
else
echo "Positional parameter 1 is empty"
fi
for all arguments :
#!/bin/bash
if [[ "$#" -gt 0 ]]; then
for arg in "$#"; do
echo $arg
done
fi
here is the image that shows the script worked
I know the question is a little older, but I can provide you with the solution.
You have to set up FileManager-actions, an extension for GNOME/Nautilus (but it also works for other file managers).
Setup filemanager-actions on Ubuntu 20.04
sudo apt update
sudo apt install filemanager-actions
Then run fma-config-tool and create a new action.
When creating an action, please ensure that:
[v] Display item in selection context menu
is flagged; otherwise, you will not see the context menu during the file selection.
Prepare the script you want to execute
Prepare a script that does what you need. Touch in /tmp, mv it in /usr/bin and give it execute permissions:
touch /tmp/your-script
# edit it with your editor
sudo mv /tmp/your-script /usr/bin/
sudo chmod +x /usr/bin/your-script
In your script, you can reference the filename using $1.
FILENAME=$1
echo $FILENAME
In the variable FILENAME you will find the selected file name.
Configure Nautilus-action command
To let nautilus pass the filename, insert the script path and the argument string in the' command' tab.
To fully answer your question, to let Nautilus pass the filename as a script argument, you have to specify %f.
At this point, quit the Nautilus instance and open it again:
nautilus -q
nautilus
Now, let's have a try! Right-click on a file and check out the result!
Appendix 1 - Filemanager-actions formats
%f A single file name, even if multiple files are selected.
%F A list of files. Each file is passed as a separate argument to the executable program.
%u A single URL. Local files may either be passed as file: URLs or as file path.
%U A list of URLs. Each URL is passed as a separate argument to the executable program.
%d Base directory
Here you can find a comprehensive list.
Appendix 2 - Sources
Check out my post blog in which I actually realize something similar: https://gabrieleserra.ml/blog/2021-08-14-filemanager-actions-ubuntu-20-04.html
Reference to all possible formats for FileManager-actions: https://askubuntu.com/a/783313/940068
Realize it in Ubuntu 18.04: https://askubuntu.com/a/77285/940068

Get current Scheme Name from Run Script Phase

Is there a way of grabbing the current scheme from a run script phase?
I've tried $(SCHEME_NAME) but it doesn't exist.
I couldn't find an environment variable to use, so I had to develop a work around: write a scheme name to disk in the Build Pre-action and then read it back out in the Run Script phase.
For each scheme you're interested in go to Edit Scheme and add a script with the following code:
rm -rf ${INTERMEDIATES_OUTPUT_DIR}
mkdir -p ${INTERMEDIATES_OUTPUT_DIR}
echo MY_SCHEME_NAME > ${SCHEME_FILE}
Next, go to your build target's "Build Settings" and add two "User-Defined Settings":
INTERMEDIATES_OUTPUT_DIR=${PROJECT_DIR}/build/intermediates/${CONFIGURATION}/
SCHEME_FILE=${INTERMEDIATES_OUTPUT_DIR}current_scheme.txt
Open up your "Run script" and add this:
SCHEME_NAME=`cat ${SCHEME_FILE}`
Be sure to add the intermediates build directory to your .gitignore file.
Obviously you could simplify this a bit by hardcoding a file name but this is a bit more robust (and we have other stuff that ends up in the intermediates directory, too).
Simplest one is set 'User Defined' variable as per scheme and use it.
You can write the scheme name to the info.plist file and read it back in Run Script Phase, in Edit Scheme menu, choose Build -> Pre-actions and add the following script:
/usr/libexec/PlistBuddy -c "Set :SchemeName \"$SCHEME_NAME\"" "$INFOPLIST_FILE"
and then add the key SchemeName of type string in the info.plist, and its initial value is empty.
Finally, in the run script phase add the following:
SCHEME_NAME=$(/usr/libexec/PlistBuddy -c "Print SchemeName" "$INFOPLIST_FILE")
INTERMEDIATES_OUTPUT_DIR doesn't seem to work for building swift previews which I wanted customization on as well. I ended up doing something similar using defaults write which I found works in all cases and doesn't involve the creation of a file.
Prebuild:
defaults write com.apple.dt.Xcode LastBuildScheme "MySchemeName"`
Build Script:
[[ $(defaults read com.apple.dt.Xcode LastBuildScheme) = "MySchemeName" ]] && echo "Scheme" || echo "Not Scheme"

How to get the files/folders in directory to show every time I change directory on Linux automatically?

I'm using Crunchbang (linux) on a virtual machine and every time I change directory I automatically do an ls to check what is there. I'm assuming that it is possible to write a script to make it do this automatically. I'm also assuming it would be a bash script of some kind, but I have maybe once written one so I wouldn't know where to start. Can anyone give me some pointers of how to go about this?
Add this to ~/.bash_profile
foo ()
{
history 1 >q
read k <q
rm q
set $k
if [ $2 = cd ]
then
ls
fi
}
PROMPT_COMMAND=foo
ref

How to run every script in a directory except itself?

I have a folder full of *.command files on my OS X workstation.
(For those that don't know, *.command files are just shell scripts that launch and run in a dedicated Terminal window).
I've dragged this folder onto my Dock to use a "stack" so I can access and launch these scripts conveniently via a couple clicks.
I want to add a new "run-all.command" script to the stack that runs all the *.command files in the same stack with the obvious exception of itself.
My Bash chops are too rusty to recall how you get a list of the *.command files, iterate them, skip the file that's running, and execute each (in this case I'd be using the "open" command so each *.command opens in its own dedicated Terminal window).
Can somebody please help me out?
How about something like this:
#! /bin/bash
for x in ./*
do
if [ "$x" != "$0" ]
then
open $x
fi
done
where $0 automatically holds the name of the script that's running
Using #bbg's original script as a starting point and incorporating the comments from #Jefromi and #Dennis Williamson, and working out some more directory prefix issues, I arrived at this working version:
#!/bin/bash
for x in "$(dirname $0)"/*.command
do
if [ "$(basename $x)" != "$(basename $0)" ]
then
open "$x"
fi
done

How do I setup automake and autoconf to conditionally build programs (tests or otherwise)

I currently have 10 tests in my autotoolset project. Any time I make a change to one of my src/ files and recompile, each test is rebuilt and linked. This is starting to have a considerable impact on my development time.
What is the best way to conditionally build binary programs, tests or otherwise, with GNU autotoolset? For instance, if I'm working in test/check_curl_requestheaders.cc, and I make a change, I am only going to want to recompile the library and then that one test and none of the other binaries.
I saw some mention of using automake conditionals (like WANTS_XXX) but I am not 100% certain that is what I'm looking for nor am I sure how that would be configured by autoconf.
I am sort of hoping for something that will end up looking like this:
./configure
make test/check_curl_requestheaders
or
./configure --only-build=test/check_curl_requestheaders
make
Pointers?
EDIT I'm not doing a configure before every make. If I make changes to check_curl_requestheaders, only check_curl_requestheaders is rebuilt as one would expect. The problem is that if I'm working on the RequestHeaders part of the library, and make a change to say, src/curl/requestheaders.cc, all of the the tests and other binaries are rebuilt, not just the check_curl_requestheaders. That is taking far too long, and that is what I am trying to avoid. If I have a dozen binaries, is there a way to rebuild only one of them?
I'm confused. In any project I've ever worked on, running 'make' from either ${top_builddir} or from ${top_builddir}/tests/ will not rebuild or run any tests. Tests are only built and executed for 'make check'. Are you using check_PROGRAMS in your Makefile.am?
In general, conditional compilation is handled with automake conditionals and Makefile.am snippets like:
if WANT_FOO
bin_PROGRAMS += foo
endif
but I'm certain this is not what you are looking for. It sounds like you have specified bogus dependencies in a Makefile.am, and you should post a minimal version of it/them.
PS: in your shell script, you can just do
export OUT
...
(cd src && make >> $OUT) || exit 3
When you change some source file, you should not have to reconfigure at all. Just run make again, and it should only rebuild those binaries that are actually affected by the change. So when you change test/check_curl_requestheaders, then do a plain make, then only test/check_curl_requestheaders should be rebuilt, anyway. If anything else gets rebuilt also, you have a bug in your makefile.
Of course, if you do configure first (which you should not), it is not surprising that more stuff gets rebuilt.
Edit: If you change the library, and then only want to rebuild a single test, then
make test/check_curl_requestheaders
should be sufficient. This would require you to have a target named test/check_curl_requestheaders in your toplevel makefile. That target may look like
test/%: library
make -C test $*
assuming you have a separate makefile in the test directory, and assuming that this makefile assumes that the library has already been built.
I'm not sure this is the best way to do this, but it turns out that the programs in my test folder did have their own unique make targets. However, there were some issues.
If I issue make at the top level, all of src/ and test/ are built
If I issue make at test/ level, changes to src/ won't be picked up
To solve this, I wrote a shell script that does the following:
Enter src, and build it. (if changes to src/ have happened, src/ is rebuilt)
Enter test, and build a specific binary. (this will rebuild the specific binary if it has changed and will relink of the code in src/ has been updated by the previous step)
The code is listed below:
#!/bin/sh
TYPE="$1"
WHICH="$2"
OUT="`readlink -f ./buildandrun.out`"
rm -rf $OUT
if test ! -n "$WHICH"
then
echo "Please specify which type to build"
exit 1
fi
if test ! -n "$WHICH"
then
echo "Please specify which $TYPE to build"
exit 2
fi
RV=0
echo "" >> $OUT
echo "Building src" >> $OUT
echo "" >> $OUT
cd src
make >> $OUT || RV=3
cd ..
if test $RV != 0; then exit $RV; fi
echo "" >> $OUT
echo "Building $TYPE/$WHICH" >> $OUT
echo "" >> $OUT
cd $TYPE
make "$WHICH" >> $OUT || RV=4
cd ..
if test $RV != 0; then exit $RV; fi
echo "" >> $OUT
echo "Running $TYPE/$WHICH" >> $OUT
echo "" >> $OUT
$TYPE/$WHICH || RV=5
exit $RV
This lets me do the following:
./buildandrun.sh test check_curl_requestheaders
Hopefully there will eventually be someone who can show me a more elegant solution to this problem, preferably using autoconf and automake. I have a feeling that this is probably something that these tools do out of the box and I just haven't discovered it yet.

Resources