0

I have written two functions into my ~/.bash_aliases file; one returns the current working folder (everything after the last / in the directory path), and one sets the terminal tab:

function set-location { printf "\e]2;$1\a"; }
function get-location {
    local location=${PWD##*/}
    echo "$location"
}

Say I am in directory james/foo/bar. Combining the two functions, I expect the terminal window to be set to bar. However, I cannot work out how to combine them effectively. I have tried the following to no avail, though I am just guessing what would work at this point:

set-location get-location # terminal title: get-location
set-location $get-location # terminal title: -location
set-location ${get-location} # terminal title: location
set-location "${get-location}" # terminal title: location
get-location | set-location # terminal title: Terminal

How do I combine these two functions in a single line, so that I can set the location to be the result of get-location?

1 Answer 1

2

Use command substitution

set-location "$(get-location)"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.