# pgfkeys: do a "local" /.cd in a style

Let's suppose I have special nodes defined that use several pgfkeys nested quite deep. I would like to use a .cd command when I define styles; but then I struggle to "go back" from the directory. Let see this example:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\tikzset{dir/two/.initial=1, dir/one/.initial=1}
\tikzset{my/.style={circle, draw, dir/.cd, one=0}}
\tikzset{my2/.style={circle, draw, dir/.cd, one=0, /tikz/.cd}}
\begin{tikzpicture}[
]
\node[my] at(0,0) {A};
\node[my, color=blue] at (1,0) {B};
\node[my2, color=blue] at (2,0) {C};
\end{tikzpicture}
\end{document}


The second node fails with

keycdup.tex|10 error| Package pgfkeys Error: I do not know the key '/tikz/dir/color', to which you passed 'blue', and I am going to ignore it. Perhaps you misspelled it.


Now, the style my2 solves the problem, with an explicit .cd to the tikz root of keys... but I fell it's not elegant at all.

Is there a way in a .style definition to "scope" the .cd command?

You could just define a key, called indir below, that uses \pgfqkeys, which seem to be made for this:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\tikzset{dir/two/.initial=1,
dir/one/.initial=1,indir/.code=\pgfqkeys{/tikz/dir}{#1}}
\tikzset{my/.style={circle, draw, indir={one=0}}}
\tikzset{my2/.style={circle, draw, dir/.cd, one=0, /tikz/.cd}}
\begin{tikzpicture}[
]
\node[my] at(0,0) {A};
\node[my, color=blue] at (1,0) {B};
\node[my2, color=blue] at (2,0) {C};
\end{tikzpicture}
\end{document}