add filteruntil

Signed-off-by: Naman Sood <mail@nsood.in>
This commit is contained in:
Naman Sood 2024-01-16 12:36:13 -05:00
parent 82c8a6aaa1
commit 1c6cc5bb5e
2 changed files with 33 additions and 0 deletions

View file

@ -9,6 +9,12 @@ DOTFILES=(
plan
)
CPP_PROGS=(
filteruntil
)
CXX="${CXX:-g++}"
echo "Setting up oh-my-zsh"
rm -rf ~/.oh-my-zsh
git clone https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh
@ -25,6 +31,12 @@ do
ln -sf $TARGET $LINK
done
for f in ${CPP_PROGS}
do
echo "Installing $f"
$CXX -std=c++23 -O3 "$(pwd)/src/$f.cpp" -o "$HOME/bin/$f"
done
mkdir -p ~/bin
for f in bin/*
do

21
src/filteruntil.cpp Normal file
View file

@ -0,0 +1,21 @@
#include <iostream>
int main(int argc, char **argv) {
if(argc != 2) {
std::cerr << "usage: " << argv[0] << " <pattern-string>" << std::endl;
return 1;
}
std::string pattern(argv[1]);
std::string line;
while(std::getline(std::cin, line)) {
if(line.find(pattern) != std::string::npos) {
break;
}
}
while(std::getline(std::cin, line)) {
std::cout << line << std::endl;
}
}